package com.kerrykidz.parreserve.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.kerrykidz.common.Constants;
import com.kerrykidz.common.ORDER_CONSTANTS;
import com.kerrykidz.common.PrimaryKeyGenerator;
import com.kerrykidz.common.PrimaryKeyGenerator.BusinessType;
import com.kerrykidz.common.service.ICommonService;
import com.kerrykidz.dao.model.GblPosDiscountEntity;
import com.kerrykidz.dao.model.LocPartyInoutEntity;
import com.kerrykidz.dao.model.SysAttFileEntity;
import com.kerrykidz.membership.dao.model.CusMemEntity;
import com.kerrykidz.parreserve.dao.model.GblParCWricorEntity;
import com.kerrykidz.parreserve.dao.model.ParCTypeEntity;
import com.kerrykidz.parreserve.dao.model.ParReserveEntity;
import com.kerrykidz.parreserve.dao.model.ParReserveRoomEntity;
import com.kerrykidz.parreserve.dao.model.ParRoomEntity;
import com.kerrykidz.parreserve.service.IParReserveService;
import com.kerrykidz.promotion.service.IPromotionService;
import com.kerrykidz.sales.dao.model.PosOrderEntity;
import com.kerrykidz.sales.dao.model.PosOrderPaymentEntity;
import com.kerrykidz.sales.dao.model.PosOrderPrdEntity;
import com.kerrykidz.sales.service.IOrderService;
import com.kerrykidz.sales.service.IPaymentService;
import com.kerrykidz.scminvoicing.dao.model.GblScmPrdCateEntity;
import com.kerrykidz.scminvoicing.dao.model.GblScmPrdEntity;
import com.kerrykidz.scminvoicing.service.IScmInvocingProductInfoService;
import com.kerrykidz.sms.service.ISmsSendService;
import com.kerrykidz.sms.util.SmsSendVO;
import com.kerrykidz.system.dao.model.GblSecBranEntity;
import com.kerrykidz.system.dao.model.SecUsrEntity;
import com.kerrykidz.system.dao.model.SysBarCodeEntity;
import com.kerrykidz.system.dao.model.SysParaEntity;
import com.kerrykidz.system.service.IReportService;
import com.kerrykidz.system.service.ISysBarCodeService;
import com.kerrykidz.system.service.IUserService;
import com.kerrykidz.system.util.DateUtil;
import com.kerrykidz.system.util.MailUtil;
import com.kerrykidz.system.util.UserUtil;
import com.kerrykidz.system.util.createWord.CreateWD2003Util;
import com.kerrykidz.system.util.createWord.model.ParHetongWordModel;
import com.kerrykidz.system.vo.ParSupperExportVo;
import com.kerrykidz.system.vo.UserInfo;
import com.rdp.framework.exception.RDPException;
import com.rdp.util.config.PropertiesUtil;
/**   
 * @Description: 派对预约 控制器
 * @Title: ParReserveController.java 
 * @Package com.kerrykidz.parreserve.controller
 * @author: chenyu   
 * @date: 2014年8月5日 
 * @version: V1.0
 *
 */
@RequestMapping("parreserve")
@Controller
public class ParReserveController {
	@Autowired
	private IReportService reportService;
	@Autowired
	private ISmsSendService iSmsSendService;
	@Autowired
	private IPaymentService iPaymentService;
	@Autowired
	private IParReserveService parReserveService;
	@Autowired 
	private IOrderService orderService;
	@Autowired 
	private IUserService userService;
	@Autowired
	private IScmInvocingProductInfoService productService;
	@Autowired
	private ISysBarCodeService iSysBarCodeService;
	@Autowired
	private IPromotionService iPromotionService;
	@Autowired
	private ICommonService commonService;
	/**
	* @Title: 派对预约页面  loadParReserve  
	* @Description: <p>派对预约页面<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/loadParReserve")
	public ModelAndView loadParReserve(HttpSession session){
		UserInfo user = UserUtil.getUserFromSession();
		String branId =user.getBranId();
		if(!"ZB".equals(branId)){
		List<ParRoomEntity> listRoom= parReserveService.findParRoom(user.getBranId());
			ModelAndView mav=new ModelAndView("membership/order_group");
			mav.addObject("listRoom", listRoom);
			mav.addObject("dateNow", DateUtil.formatDate("yyyy-MM-dd",new Date()));
			return mav;
		}else{
			ModelAndView mav=new ModelAndView("noAuthority");
			return mav;
		}
		
	}
	
	/**
	* @Title:  派对预约详细页面  parReserveDetail  
	* @Description: <p>派对预约详细页面<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/parReserveDetail")
	public ModelAndView parReserveDetail(@RequestParam("parType") String parType,@RequestParam("pkParresId") String pkParresId,
			@RequestParam("pkOrderId") String pkOrderId,HttpSession session) throws RDPException{
			ModelAndView mav=new ModelAndView("membership/order_add_x");
			String basicPkg="";
			ParReserveEntity parreserve=null;
			List<ParReserveRoomEntity> parReserveRoomList=new ArrayList<ParReserveRoomEntity>();
			if(StringUtils.isNotBlank(pkParresId)){
			  parreserve=parReserveService.findParReserveById(pkParresId);
			  parreserve.setPresDay(DateUtil.formatDate("yyyy-MM-dd", parreserve.getResDay()));
			  parReserveRoomList= parReserveService.findParReserveRoomByparId(pkParresId);
			  basicPkg =parreserve.getBasicPkg();
			}
			
			String guanliDetail="";
			List<ParCTypeEntity> cTypeList= parReserveService.findParCtypeList();
			if(StringUtils.isNotBlank(pkOrderId) && pkOrderId.indexOf("@")>0){//档案管理 --》派对，团体预约 详细页面 点击 过来的 ，订单Id
				String[] pkorderIds =pkOrderId.split("@");
				guanliDetail="guanliDetail";
				if(pkorderIds.length>1){
					pkOrderId = pkorderIds[1];
				}else{
					pkOrderId ="";
				}
			}
			
			mav.addObject("parReserveRoomList", parReserveRoomList);
			mav.addObject("pkParresId", pkParresId);
			mav.addObject("pkOrderId", pkOrderId);
			mav.addObject("cTypeList", cTypeList);
			mav.addObject("guanliDetail", guanliDetail);//此参数  方便 ，返回 到 档案管理 --》预约管理 页面
			mav.addObject("parreserveOld", parreserve);
			mav.addObject("parType", parType); 
				return loadDataList( mav, parType,basicPkg,session,parreserve);
	}
	
	/**
	* 团体预约详细页面  parReserveDetail  
	* @Description: <p>团体预约详细页面<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/tuanReserveDetail")
	public ModelAndView tuanReserveDetail(@RequestParam("parType") String parType,
			@RequestParam("pkParresId") String pkParresId,@RequestParam("pkOrderId") String pkOrderId,HttpSession session)throws RDPException{ 
		ModelAndView mav=new ModelAndView("membership/order_add");
		ParReserveEntity parreserve=null;
		String basicPkg="";
		List<ParReserveRoomEntity> parReserveRoomList=new ArrayList<ParReserveRoomEntity>();
		if(StringUtils.isNotBlank(pkParresId)){
		  parreserve=parReserveService.findParReserveById(pkParresId);
		  basicPkg =parreserve.getBasicPkg();
		  parreserve.setPresDay(DateUtil.formatDate("yyyy-MM-dd", parreserve.getResDay()));
		  parReserveRoomList= parReserveService.findParReserveRoomByparId(pkParresId);
		  
		}
		String guanliDetail="";
		if(StringUtils.isNotBlank(pkOrderId) && pkOrderId.indexOf("@")>0){//档案管理 --》派对，团体预约 详细页面 点击 过来的 ，订单Id
			String[] pkorderIds =pkOrderId.split("@");
			guanliDetail="guanliDetail";
			if(pkorderIds.length>1){
				pkOrderId = pkorderIds[1];
			}else{
				pkOrderId ="";
			}
			
		}
		mav.addObject("parReserveRoomList", parReserveRoomList);
		mav.addObject("pkParresId", pkParresId);
		mav.addObject("pkOrderId", pkOrderId);
		mav.addObject("guanliDetail", guanliDetail);//此参数  方便 ，返回 到 档案管理 --》预约管理 页面
		mav.addObject("parreserveOld", parreserve);
		mav.addObject("parType", parType); 
			return loadDataList( mav, parType,basicPkg,session,parreserve);
		
	}
	
	/**
	 *  初始化 加载 派对，团体 预约 详细 页面  的 套餐，附加菜单，装饰物 列表
		 * @Description   
		 * ModelAndView
		 * @author chenyu
		 * 2014年8月21日 下午1:58:51
	 */
	public ModelAndView loadDataList(ModelAndView mav, String parType,String basicPkg,HttpSession session,ParReserveEntity parreserve) throws RDPException{
		UserInfo user = UserUtil.getUserFromSession();
		List<ParRoomEntity> listRoom= parReserveService.findParRoom(user.getBranId());
		HashMap<String,Object> gblprdMap =new HashMap<String,Object>();
		List<GblScmPrdEntity> listGblScmTaocan=null;
		
		//================更改日期 判断
		String showDaycontrols ="";
		List<String> dateDayCountList =null;
		/**
		if(null !=parreserve){
//			String creaTime =DateUtil.formatDate("yyyy-MM-dd", parreserve.getCreaTime()); 
//			String nowTime =DateUtil.formatDate("yyyy-MM-dd", new Date());
			//if(!creaTime.equals(nowTime)){
			if(null !=parreserve.getResDay()){
				int dayc = DateUtil.getDiffDays(new Date(),parreserve.getResDay());
				 
				if(dayc<15){//3)举办日期在15之内，不允许改期
					showDaycontrols="lessFifteen";
				}else{//1)举办日期>=15天后，改期后的举办日期必选>=15天
					if(parreserve.getGrpFlag().equals("0")){//派对在此处 派对 ，团体为了 方便 在下面 的 假期日期findValidHoliday方法中判断
				     	dateDayCountList =DateUtil.getDateByDayCountList(15,new Date());
					}
					showDaycontrols="moreFifteen";
 				}
			}
		//}
		}
		//================
		**/
		if(StringUtils.isBlank(basicPkg)){
		gblprdMap.put("cateId1", Constants.RESERVE_PRDCATE_CODEFOOD);// 派对主食1 :冷食
		gblprdMap.put("cateId2", Constants.RESERVE_PRDCATE_HOTFOOD);// 派对主食2：热食
		gblprdMap.put("cateId3", Constants.RESERVE_PRDCATE_PEICAI);// 派对配菜
		gblprdMap.put("cateId4", Constants.PRDCATE_DRINK);//派对饮料
		GblScmPrdEntity gblscmprd=new GblScmPrdEntity();
		gblscmprd.setParams(gblprdMap);
		if("1".equals(parType)){
			gblprdMap.put("parZhuShiCount", 1);
			gblscmprd.setPageSize(4);
		}else if("0".equals(parType)){
			gblprdMap.put("parZhuShiCount",2);//派对套餐可选三道主食 、 一 道配菜 和一份饮料
			gblscmprd.setPageSize(5);
		}
		  listGblScmTaocan = parReserveService.findParReserveTaocan(gblscmprd);
		}else{
			listGblScmTaocan =getUpdateTaocanList(basicPkg,parType);
		}
		GblScmPrdEntity entity=new GblScmPrdEntity();
		List<GblScmPrdCateEntity> cateList=productService.recurseCate(Constants.RESERVE_PRDCATE_HOTFOOD, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblZhuRe = parReserveService.findParReserveTaocanByCateId(entity);
		
		  cateList=productService.recurseCate(Constants.RESERVE_PRDCATE_CODEFOOD, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblZhuLeng = parReserveService.findParReserveTaocanByCateId(entity);
		
		 cateList=productService.recurseCate(Constants.RESERVE_PRDCATE_PEICAI, true, true);
			entity.setPrdStatus("1");
			entity.setCateList(cateList);
		List<GblScmPrdEntity>  listGblpeicai = parReserveService.findParReserveTaocanByCateId(entity);

		  cateList=productService.recurseCate(Constants.PRDCATE_DRINK, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblparYinliao = parReserveService.findParReserveTaocanByCateId(entity);
		 mav.addObject("listGblScmTaocan", listGblScmTaocan);
		mav.addObject("listGblZhuRe", listGblZhuRe);
		mav.addObject("listGblZhuLeng", listGblZhuLeng);
		mav.addObject("listGblpeicai", listGblpeicai);
		mav.addObject("listGblparYinliao", listGblparYinliao);
		mav.addObject("gblScmTaocanSize", listGblScmTaocan.size());
		
		

		  cateList=productService.recurseCate(Constants.RESERVE_PRDCATE_F_HOTFOOD, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblFUjiaRe = parReserveService.findParReserveTaocanByCateId(entity);

		  cateList=productService.recurseCate(Constants.RESERVE_PRDCATE_F_CODEFOOD, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblFUjiaLeng = parReserveService.findParReserveTaocanByCateId(entity);

		  cateList=productService.recurseCate(Constants.RESERVE_PRDCATE_F_PEICAI, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity>  listGblFUjiapeicai = parReserveService.findParReserveTaocanByCateId(entity);

		  cateList=productService.recurseCate(Constants.PRDCATE_F_DRINK, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblparFUjiaYinliao = parReserveService.findParReserveTaocanByCateId(entity);

		  cateList=productService.recurseCate(Constants.PRDCATE_F_DESSERT, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblparFUjiaTdian = parReserveService.findParReserveTaocanByCateId(entity);

		  cateList=productService.recurseCate(Constants.PRDCATE_F_WINE, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblparFUjiaWine = parReserveService.findParReserveTaocanByCateId(entity);
//		mav.addObject("listGblScmFujia", listGblScmFujia);
		mav.addObject("listGblFUjiaRe", listGblFUjiaRe);
		mav.addObject("listGblFUjiaLeng", listGblFUjiaLeng);
		mav.addObject("listGblFUjiapeicai", listGblFUjiapeicai);
		mav.addObject("listGblparFUjiaYinliao", listGblparFUjiaYinliao);
		mav.addObject("listGblparFUjiaTdian", listGblparFUjiaTdian);
		mav.addObject("listGblparFUjiaWine", listGblparFUjiaWine);
		

		  cateList=productService.recurseCate(Constants.RESERVE_PRDCATE_QIQIU, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity>  listGblTrimmingQiqiu = parReserveService.findParReserveTaocanByCateId(entity);

		  cateList=productService.recurseCate(Constants.RESERVE_PRDCATE_DINGZHI, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblTrimmingDingzhi = parReserveService.findParReserveTaocanByCateId(entity);

		  cateList=productService.recurseCate(Constants.RESERVE_PRDCATE_CEGGS, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblTrimmingCDan = parReserveService.findParReserveTaocanByCateId(entity);

		  cateList=productService.recurseCate(Constants.PRDCATE_PERFORM, true, true);
		entity.setPrdStatus("1");
		entity.setCateList(cateList);
		List<GblScmPrdEntity> listGblTrimmingBiao = parReserveService.findParReserveTaocanByCateId(entity);
		mav.addObject("listGblTrimmingQiqiu", listGblTrimmingQiqiu);
		mav.addObject("listGblTrimmingDingzhi", listGblTrimmingDingzhi);
		mav.addObject("listGblTrimmingCDan", listGblTrimmingCDan);
		mav.addObject("listGblTrimmingBiao", listGblTrimmingBiao);
		mav.addObject("modiName", user.getName());
		mav.addObject("modiBy", user.getUserId());
			for(int i=0;i<listRoom.size();i++){
				mav.addObject("roomf"+i, listRoom.get(i));
			}
			mav.addObject("listRoom", listRoom);
			mav.addObject("showDaycontrols", showDaycontrols);
			mav.addObject("dateDayCountList", dateDayCountList);
			String disableIsShow="";
			 if(null !=parreserve && StringUtils.isNotBlank(parreserve.getResStatus())){
				 int resStatus=Integer.parseInt(parreserve.getResStatus());
				 if(resStatus>1){
					 disableIsShow ="disabled";
				 }
			 }
			 mav.addObject("disableIsShow", disableIsShow);
		return mav;
	}
	/**
	* @Title:  修改主食 配菜 弹出页面  updateZhushi  
	* @Description: <p>修改主食 配菜 弹出<p>
	* @date: 2014年8月6日
	* @return: ModelAndView
	* @author chenyu
	* @throws 
	*
	 */
	@RequestMapping("/updateZhushi")
	@ResponseBody
	public HashMap<String, Object> updateZhushi(HttpSession session,ParReserveEntity parReserve){
		String pkParresId =parReserve.getPkParresId();
		parReserve.setResDay(DateUtil.getDate(parReserve.getPresDay()));
		parReserve.setModiTime(new Date());
		parReserve.setResStatus(Constants.RESERVE_STATUS_NOPREPAY);
		String abbrCode = UserUtil.getUserFromSession().getAbbrCode();// 门店缩写
		String branId = UserUtil.getUserFromSession().getBranId();// 门店编号
		parReserve.setFkBranId(branId); 
		 String[] roomIds =parReserve.getRoomIds().split(",");
		 String roomIdValue="";
		 for(int i=0;i<roomIds.length;i++){
			 if(i==roomIds.length-1){
				 roomIdValue+="'"+roomIds[i]+"'";
			 }else{
			   roomIdValue+="'"+roomIds[i]+"',";
			 }
		 }
		 parReserve.setRoomId(roomIdValue);
		if(StringUtils.isBlank(pkParresId)){
			pkParresId = PrimaryKeyGenerator.getPrimaryKey(BusinessType.YY, abbrCode);
			parReserve.setPkParresId(pkParresId);
			parReserveService.insertParReserve(parReserve);
		}else{
			parReserveService.updateParReserve(parReserve);
		}
		//===添加房间 预约关系 
		addParResRoom(parReserve,roomIds);
		//====
		List<GblScmPrdEntity> listUpdateScmTaocan=new ArrayList<GblScmPrdEntity>();
		if(  !parReserve.getBasicPkg().equals(Constants.RESERVE_PRDCATE_4NOMEAL+"#")){
			 listUpdateScmTaocan =getUpdateTaocanList(parReserve.getBasicPkg(),parReserve.getGrpFlag());
		}
		HashMap<String, Object> jsonmap=new HashMap<String, Object>();
		jsonmap.put("pkParresId", pkParresId);
		jsonmap.put("listUpdateScmTaocan", listUpdateScmTaocan);
		return 	jsonmap;
		
	}
	
	/**
	 * 修改套餐 后的 list
		 * @Description   
		 * List<GblScmPrdEntity>
		 * @author chenyu
		 * 2014年8月21日 下午2:00:34
	 */
	public List<GblScmPrdEntity> getUpdateTaocanList(String basicPkg,String parType){
		List<String> proIdList =new ArrayList<String>();
		List<GblScmPrdEntity> listUpdateScmTaocan=new ArrayList<GblScmPrdEntity>();
		if(  !basicPkg.equals(Constants.RESERVE_PRDCATE_4NOMEAL+"#")){//  含餐
		   String[] basicpkg1= basicPkg.split("#");
		   if(basicpkg1.length>1 && StringUtils.isNotBlank(basicpkg1[1])){
				String[] productidArray =basicpkg1[1].split(",");
				for(int i=0;i<productidArray.length;i++){
					if(StringUtils.isBlank(productidArray[i])){
						continue;
					}else{
				    	proIdList.add(productidArray[i]);
					}
				}
				HashMap<String,Object> gblprdMap =new HashMap<String,Object>();
				gblprdMap.put("type", 1);//1 主食套餐
				gblprdMap.put("proIdList", proIdList);
				  listUpdateScmTaocan = parReserveService.findScmRrdByprdIdList(gblprdMap);
		   }
		   }else{//默认 主食套餐
				HashMap<String,Object> gblprdMap =new HashMap<String,Object>();
				gblprdMap.put("cateId1", Constants.RESERVE_PRDCATE_CODEFOOD);// 派对主食1 :冷食
				gblprdMap.put("cateId2", Constants.RESERVE_PRDCATE_HOTFOOD);// 派对主食2：热食
				gblprdMap.put("cateId3", Constants.RESERVE_PRDCATE_PEICAI);// 派对配菜
				gblprdMap.put("cateId4", Constants.PRDCATE_DRINK);//派对饮料
				GblScmPrdEntity gblscmprd=new GblScmPrdEntity();
				gblscmprd.setParams(gblprdMap);
				if("1".equals(parType)){
					gblprdMap.put("parZhuShiCount", 1);
					gblscmprd.setPageSize(4);
				}else if("0".equals(parType)){
					gblprdMap.put("parZhuShiCount",2);//派对套餐可选三道主食 、 一 道配菜 和一份饮料
					gblscmprd.setPageSize(5);
				}
				listUpdateScmTaocan = parReserveService.findParReserveTaocan(gblscmprd);
		   }

		return listUpdateScmTaocan;
	}
	/**
	* @Title:  预约 下单结算 预约付款到数据库 
	* @Description: <p> 预约 下单结算 预约付款到数据库  <p>
	* @date: 2014年8月6日
	* @return:  HashMap<String,Object>
	* @author chenyu
	* @throws 
	*
	 */
	@RequestMapping("/parOrderPayMent")
	@ResponseBody
	public  HashMap<String,Object> parOrderPayMent(HttpSession session,ParReserveEntity parReserve) throws Exception{
//		 parReserve.setResStatus(Constants.RESERVE_STATUS_TOBECONFIRM);
		String pkParresid=parReserve.getPkParresId();
		double paidAmount =parReserve.getPaidAmount();
		 parReserveService.updateParReserve(parReserve);
		 parReserve = parReserveService.findParReserveById(pkParresid);
		 parReserve.setPaidAmount(paidAmount);
		return operateOrder(session,parReserve,ORDER_CONSTANTS.ORDER_STATUS_PREPAY,null,null,false,null);
		
	}
	
	
	/**
	* @Title:  团体确认预定（保留预约） 此时 预付款为0 到数据库 
	* @Description: <p> 团体确认预定（保留预约） 此时 预付款为0 到数据库  <p>
	* @date: 2014年8月6日
	* @return:  HashMap<String,Object>
	* @author chenyu
	* @throws 
	*
	 */
	@RequestMapping("/okparTuantiOrderPayMent")
	@ResponseBody
	public  HashMap<String,Object> okparTuantiOrderPayMent(HttpSession session,
			 @RequestParam(value="operatetype") String operatetype,@RequestParam(value="pkParresId") String pkParresId) throws Exception{
		ParReserveEntity parReserve = parReserveService.findParReserveById(pkParresId); 
		if(operatetype.equals("save")){
			parReserve.setResStatus(Constants.RESERVE_STATUS_CONFIRMED);
			parReserveService.updateParReserve(parReserve);
			return okparTuantiOperateOrder(session,parReserve,"",null,null,false,null,"6");//=6 派对团体未结算
		}else{//取消
			 parReserve.setResStatus(Constants.RESERVE_STATUS_CANCEL);
			 parReserveService.updateParReserve(parReserve);
			 List<PosOrderEntity> posOrderList =null;
				posOrderList =parReserveService.findPosOrderByParresId(pkParresId);
				if(null !=posOrderList && posOrderList.size()>0){
					PosOrderEntity posOrderOld =posOrderList.get(0);
					if(null !=posOrderOld){
						posOrderOld.setOrderStatus(ORDER_CONSTANTS.ORDER_STATUS_CANCEL);//取消
						 orderService.updateOrder(posOrderOld);
					}
					}
			 HashMap<String,Object> putObj=new HashMap<String,Object>();
				putObj.put("cancel", "cancel");
			 return putObj;
		}
	}
	
	/**
	 * 点击 “成员条码” 按钮时，初始分配 条码 到团体预约入场表
		 * @Description   
		 * Map<String,Object>
		 * @author chenyu
		 * 2014年9月15日 下午4:28:25
	 */
	@RequestMapping("/initAddSysCode")
	@ResponseBody
	public Map<String, Object> initAddSysCode(HttpSession session,@RequestParam(value="pkParresId") String pkParresId,
			@RequestParam(value="resMemCnt") String resMemCnts) {
		LocPartyInoutEntity localPartyInout = new LocPartyInoutEntity();
		UserInfo user = UserUtil.getUserFromSession();
		String abbrCode = user.getAbbrCode();// 门店缩写
		int resMemCnt =Integer.parseInt(resMemCnts);
		int truesysCode=-1; //有效的 条码数量
		Map<String, Object> mapResult =new HashMap<String,Object>();
		List<LocPartyInoutEntity> locPartyInoutList = parReserveService.selectLocParTyInOutByParresId(pkParresId);
		if (null != locPartyInoutList && locPartyInoutList.size() == resMemCnt) {

		} else {
			
			if(null !=locPartyInoutList){
				resMemCnt =resMemCnt -locPartyInoutList.size();
			}
			 if(resMemCnt >0){
			Map<String, Object> mapc = new HashMap<String, Object>();
			SysBarCodeEntity sysBarCodec = new SysBarCodeEntity();
			sysBarCodec.setFkBranId(user.getBranId());
			sysBarCodec.setUsableCount(resMemCnt);
			List<SysBarCodeEntity> sysBarCodeList = parReserveService.findSysBarCodeListByBranId(sysBarCodec);
			if (null != sysBarCodeList && sysBarCodeList.size() > 0) {
				mapc.put("status", "1");// （条码是否被占用的标记=1 占用，=0 未占用）
				mapc.put("barCodeList", sysBarCodeList);
				mapc.put("type", "initBcode");
				iSysBarCodeService.updateBcodeStatusBatch(mapc);

				for (SysBarCodeEntity sysBarCode : sysBarCodeList) {
					localPartyInout = new LocPartyInoutEntity();
					String PkPartyIoId = PrimaryKeyGenerator.getPrimaryKey(BusinessType.PA, abbrCode);
					localPartyInout.setPkPartyIoId(PkPartyIoId);
					localPartyInout.setOperateBy(user.getUserId());
					localPartyInout.setFkParresId(pkParresId);
					localPartyInout.setFkBranId(user.getBranId());
					localPartyInout.setFkBcodeId(sysBarCode.getPkBcodeId());
					parReserveService.addLocParTyInOut(localPartyInout);
				}
				if(resMemCnt>sysBarCodeList.size()){
					truesysCode =sysBarCodeList.size();
				}
			}else{
				truesysCode  =0;
				
			}
		 }
			 locPartyInoutList = parReserveService.selectLocParTyInOutByParresId(pkParresId);
		}
		
		mapResult.put("locPartyInoutList", locPartyInoutList);
		mapResult.put("truesysCode", truesysCode);
		return mapResult;
	}
	
	/**
	 * 修改 成员条码
		 * @Description   
		 * Map<String,Object>
		 * @author chenyu
		 * 2014年9月15日 下午4:28:25
	 */
	@RequestMapping("/updateSyscode")
	@ResponseBody
	public String updateSyscode(HttpSession session,@RequestParam(value="pkPartyIoId") String pkPartyIoId,
			@RequestParam(value="codeValue") String codeValue) throws RDPException{
		SysBarCodeEntity entitySysBarCode =new SysBarCodeEntity();
		entitySysBarCode.setBarCode(codeValue);
		entitySysBarCode.setFkBranId(UserUtil.getUserFromSession().getBranId());
		List<SysBarCodeEntity> sysBarCodeList = parReserveService.selectSBarCodeBrandId(entitySysBarCode);
		String msgResult ="";
		if(null ==sysBarCodeList || sysBarCodeList.size()==0){
			msgResult ="2@";// 系统中不存在 此条形码，请正确输入，【 此条形码 或停用，或占用中，或不存在】。
		}else{
			String bcodeId =sysBarCodeList.get(0).getPkBcodeId();
		    msgResult ="1@"+bcodeId;
			LocPartyInoutEntity localPartyInout = new LocPartyInoutEntity();
			localPartyInout.setPkPartyIoId(pkPartyIoId);
			localPartyInout.setFkBcodeId(bcodeId);
			localPartyInout.setOperateBy(UserUtil.getUserFromSession().getUserId());
			parReserveService.updateLocParTyInOut(localPartyInout);
		}
		return msgResult;
	}
	
	/**
	 * insert,update 预约订单
		 * @Description   
		 * HashMap<String,Object>
		 * @author chenyu
		 * 2014年8月21日 下午2:01:33
	 */
	HashMap<String,Object> operateOrder(HttpSession session,ParReserveEntity parReserve,String orderStatus,
			List<ParReserveRoomEntity> reserveRoomList,Double oldPaidAmount,boolean copyHisFlag,
			ParReserveEntity parReserveOld ) throws Exception{
		String abbrCode = UserUtil.getUserFromSession().getAbbrCode();// 门店缩写
		String branId = UserUtil.getUserFromSession().getBranId();// 门店编号
		String userId = UserUtil.getUserFromSession().getUserId();
		String pkParresId =parReserve.getPkParresId();
		String orderPk=parReserve.getPkOrderId();
		boolean isTuantiyuding =false;//团体确认预定 标志。
		List<PosOrderEntity> posOrderList =null;
		if(StringUtils.isBlank(orderPk)){
			posOrderList =parReserveService.findPosOrderByParresId(pkParresId);
			
			if(null !=posOrderList && posOrderList.size()>0){
				PosOrderEntity posOrderOld =posOrderList.get(0);
				if(null !=posOrderOld){
					orderPk =posOrderOld.getPkOrderId();
					parReserve.setPkOrderId(orderPk);
					if(StringUtils.isBlank(orderStatus)){
						isTuantiyuding =true;
						orderStatus =ORDER_CONSTANTS.ORDER_STATUS_NOT_PAY;//团体确认预定 时，订单状态设置 未付款
					}
				}
			}
		}
		if(StringUtils.isBlank(orderStatus)){// 当 预约 未生成 订单时 的设置
			isTuantiyuding =true;
			orderStatus ="7";
		}
		List<PosOrderPrdEntity> products =null;
		double amount=0.00;
		double zhucanPrice =0;
		if(orderStatus.equals(ORDER_CONSTANTS.ORDER_STATUS_NOT_PAY) ||orderStatus.equals(ORDER_CONSTANTS.ORDER_STATUS_PREPAY)|| orderStatus.equals("7")){//未付款,草稿状态时，可以批量修改订单明细
		  products =new ArrayList<PosOrderPrdEntity>();
		if(StringUtils.isNotBlank(parReserve.getBasicPkg())  ){
			String basicPkgs[] =parReserve.getBasicPkg().split("#");
			  zhucanPrice =parReserveService.findPrdPriceByPrdId(basicPkgs[0]);
			PosOrderPrdEntity posOrderPrd=new PosOrderPrdEntity();
			posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
			posOrderPrd.setFkPrdId(basicPkgs[0]);
			int pcount =parReserve.getResMemCnt();
			posOrderPrd.setOrdIndex(1);
			posOrderPrd.setPrice(zhucanPrice);
			posOrderPrd.setDisPrice(zhucanPrice*pcount);
			posOrderPrd.setPkOrderId(orderPk);
			
			posOrderPrd.setCount(pcount);
			amount+=zhucanPrice*pcount;
			products.add(posOrderPrd);
		}
		int i=1;
		if(StringUtils.isNotBlank(parReserve.getBasicPkg2())){
			String basicPkgs2[] =parReserve.getBasicPkg2().split(",");
			for(String basicPkg2:basicPkgs2){
				i++;
				PosOrderPrdEntity posOrderPrd=new PosOrderPrdEntity();
				posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
				if(StringUtils.isNotBlank(basicPkg2)){
					String basicPkg2Ids[]=basicPkg2.split("#");
					if(StringUtils.isNotBlank(basicPkg2Ids[1]) && Integer.parseInt(basicPkg2Ids[1])>0){
						double fujiaPrice =parReserveService.findPrdPriceByPrdId(basicPkg2Ids[0]);
						int pcount=Integer.parseInt(basicPkg2Ids[1]);
						posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
						posOrderPrd.setFkPrdId(basicPkg2Ids[0]);
						posOrderPrd.setOrdIndex(i);
						posOrderPrd.setPrice(fujiaPrice);
						posOrderPrd.setDisPrice(fujiaPrice * pcount);
						posOrderPrd.setPkOrderId(orderPk);
						posOrderPrd.setCount(Integer.parseInt(basicPkg2Ids[1]));
						amount+=fujiaPrice * pcount;
						products.add(posOrderPrd);
					}
				}
			}
		}
		if(StringUtils.isNotBlank(parReserve.getBasicPkg3())){
			String basicPkgs3[] =parReserve.getBasicPkg3().split(",");
			for(String basicPkg3:basicPkgs3){
				i++;
				PosOrderPrdEntity posOrderPrd=new PosOrderPrdEntity();
				posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
				if(StringUtils.isNotBlank(basicPkg3)){
					String basicPkg3Ids[]=basicPkg3.split("#");
					if(StringUtils.isNotBlank(basicPkg3Ids[1]) && Integer.parseInt(basicPkg3Ids[1])>0){
						double qiQiuPrice =parReserveService.findPrdPriceByPrdId(basicPkg3Ids[0]);
						int pcount =Integer.parseInt(basicPkg3Ids[1]);
						posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
						posOrderPrd.setFkPrdId(basicPkg3Ids[0]);
						posOrderPrd.setPkOrderId(orderPk);
						posOrderPrd.setOrdIndex(i);
						posOrderPrd.setPrice(qiQiuPrice);
						posOrderPrd.setDisPrice(qiQiuPrice * pcount);
						posOrderPrd.setCount(pcount);
						amount+=qiQiuPrice * pcount;
						products.add(posOrderPrd);
					}
				}
			}
		}
		
		if(null!= parReserve.getOverTime() && 0<parReserve.getOverTime()){// 客户 选中 加时 
			String fkOtprdId  =parReserve.getFkOtprdId();
			if(StringUtils.isNotBlank(fkOtprdId)){
				PosOrderPrdEntity posOrderPrd=new PosOrderPrdEntity();
				int pcount =parReserve.getOverTime();
				double jiashiPrice =parReserveService.findPrdPriceByPrdId(fkOtprdId);
				posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
				posOrderPrd.setFkPrdId(fkOtprdId);
				posOrderPrd.setPkOrderId(orderPk);
				posOrderPrd.setOrdIndex(i+1);
				posOrderPrd.setPrice(jiashiPrice);
				posOrderPrd.setDisPrice(jiashiPrice * pcount);
				posOrderPrd.setCount( pcount);
				amount+=jiashiPrice * pcount;
				products.add(posOrderPrd);
			}
		}
		}
		
		PosOrderEntity order=new PosOrderEntity();
		order.setOrderType(ORDER_CONSTANTS.ORDER_TYPE_PARTY);
		order.setFkParresId(pkParresId);
		order.setOrderStatus(orderStatus);//订单状态
		order.setCusName(parReserve.getConName());
		order.setFkOperator("");
		order.setModiBy(parReserve.getModiBy());
		order.setModiTime(new Date());
		order.setRetFlag("0");//是否是退单的标记   =0 否 
		if(null !=parReserve.getAmount() && parReserve.getAmount()>0){
			order.setAmount(parReserve.getAmount());
		}else{
			order.setAmount(amount);
		}
		double newPaidAmount =0.0;
        if(null == parReserve.getPaidAmount() && !isTuantiyuding  && null !=reserveRoomList){
        	 newPaidAmount =getpaidAmount(reserveRoomList,zhucanPrice);
        	 order.setPaidAmount(newPaidAmount);
        }else{
        	order.setPaidAmount(parReserve.getPaidAmount());
        }
        if(isTuantiyuding){
        	order.setOrderStatus(orderStatus);//订单状态
        	order.setPaidAmount(0.0);
        }
        if(StringUtils.isNotBlank(parReserve.getFkParcpnId())){
        	order.setFkParcpnId(parReserve.getFkParcpnId());
        }
        Date dateNow =new Date();
        order.setModiBy(userId);
        order.setModiTime(dateNow);
        order.setFkOperator(userId);
		order.setOperateTime(dateNow);
		order.setFkBranId(branId);
		order.setPkOrderId(parReserve.getPkOrderId());
		String OldpkOrderId =parReserve.getPkOrderId();
		if(null !=oldPaidAmount && null !=reserveRoomList && copyHisFlag){
			 newPaidAmount =getpaidAmount(reserveRoomList,zhucanPrice);
			//3 如果新订单需要预付定金，新订单状态“未预付”，原订单状态保持不变直至新订单预付成功后，原订单“取消”；24小时之内新订单未预付，新订单删除
			if(newPaidAmount> oldPaidAmount){
				order.setOrderStatus(ORDER_CONSTANTS.ORDER_STATUS_PREPAY);//  新订单状态“未预付”
				order.setPaidAmount(newPaidAmount);
			
				
				 orderPk=orderService.createNotPayOfOrder(order, products, abbrCode);
				
			}else{
				
				String oldstatusOrder=ORDER_CONSTANTS.ORDER_STATUS_PREPAY;
				if(null !=parReserveOld){
					String pkOldrParReserveId =parReserveOld.getPkParresId();//老的 预约编号
					posOrderList =parReserveService.findPosOrderByParresId(pkOldrParReserveId);//老订单
					if(null !=posOrderList && posOrderList.size()>0){
						PosOrderEntity posOrderOld =posOrderList.get(0);
					if(null !=posOrderOld){
						oldstatusOrder =posOrderOld.getOrderStatus();
					}
					}
				}
				//2. 如果新订单不需要重新预付定金，新订单状态为“预付”，原订单“取消”
				order.setOrderStatus(oldstatusOrder);//  新订单状态“预付”
				order.setPaidAmount(newPaidAmount);
				 orderPk=orderService.createNotPayOfOrder(order, products, abbrCode);
				 posOrderList = parReserveService.findPosOrderByParresId(parReserve.getFkPriorresId());
				 if(null !=posOrderList && posOrderList.size()>0){
					 PosOrderEntity orderOld =posOrderList.get(0);
					 if(null !=orderOld){
						 
						 orderService.removeOrderPrdByOrderId(orderOld.getPkOrderId());
						 orderOld.setOrderStatus(ORDER_CONSTANTS.ORDER_STATUS_CANCEL);
						 orderOld.setModiTime(new Date());
						 orderService.updateOrder(orderOld);
						 if(null !=parReserveOld){
							 parReserveService.deleteParRoomByParId(parReserveOld.getPkParresId());//先删除老的 房间记录
							 parReserveOld.setResStatus(Constants.RESERVE_STATUS_CANCEL);
							 parReserveService.updateParReserve(parReserveOld);
						 }
					 }
				 }
			}
		}else{
			if(StringUtils.isNotBlank(orderPk)){
				if(null ==products){
				   orderService.updateOrder(order);
				}else{
					order.setModiTime(new Date());
			    	orderService.updateOrder(order, products);
				}
			}else{
				order.setOrderStatus("7");//订单草稿状态
			  orderPk=orderService.createNotPayOfOrder(order, products, abbrCode);
			}
		}
		if(null !=parReserveOld){
		String pkOldrParReserveId =parReserveOld.getPkParresId();//老的 预约编号
		if(parReserve.getPkParresId().equals(parReserveOld.getPkParresId())){
			pkOldrParReserveId =parReserveOld.getFkPriorresId();
		}
		List<PosOrderPaymentEntity> NeworderPaymentList =iPaymentService.findByOrderPk(orderPk);//新订单支付记录列表
		posOrderList =parReserveService.findPosOrderByParresId(pkOldrParReserveId);//老订单
		if(null !=posOrderList && posOrderList.size()>0){
			PosOrderEntity posOrderOld =posOrderList.get(0);
		if(null !=posOrderOld){
			List<PosOrderPaymentEntity> orderPaymentList =iPaymentService.findByOrderPk(posOrderOld.getPkOrderId());//老订单支付记录列表
				 if(null !=orderPaymentList && orderPaymentList.size()>0){
					 if(null ==NeworderPaymentList || NeworderPaymentList.size()< orderPaymentList.size()){// 当新订单支付记录为空时，从老订单记录copy过来
					 for(int pp=0;pp<orderPaymentList.size();pp++){
						 PosOrderPaymentEntity payment=orderPaymentList.get(pp);
						 payment.setFkOrderId(orderPk);
						 iPaymentService.createRepay(payment);
					 }
					 }
				 }
			}
			}
		}
		if(null!=order && order.getOrderStatus().equals(ORDER_CONSTANTS.ORDER_STATUS_PREPAY)){
			SmsSendVO smsVo =new SmsSendVO();
			smsVo.setSmsMob(parReserve.getConMobile());
			String msg ="亲爱的客户您好，很高兴能为您提供派对服务，请在未来24小时内完成派对定金支付，我们将为您的派对做充足的准备，逾期则自动取消，谢谢，无锡昕星园。";
			smsVo.setSmsText(msg);
			iSmsSendService.sendSMS(smsVo);//发短信
			
			// 发Email
			String comEmail =parReserve.getConEmail();
			if(StringUtils.isNotBlank(parReserve.getConEmail())){
				Pattern pattern = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
				Matcher matcher = pattern.matcher(comEmail);
				 if(matcher.matches()){
					 msg ="";
					 msg="亲爱的客户您好，<br/>";
					 msg +="昕星园很高兴能为您提供专业的儿童派对服务，我们已向系统提交了您的派对预定，请您在收到我们邮件后的24小时内至昕星园完成派对定金预付，我们将会为您的派对做充足的准备。温馨提示：预期未进行预付系统将自动取消该预定。<br/>";
					 msg +="感谢您对我们的信任，我们将竭力为您的孩子及您邀请的亲友举办一场愉快难忘的派对。<br/>";
					 msg +="欢迎你们来到昕星园!<br/>"; 
					 msg +="派对预定电话：0510-81833508"; 
					 MailUtil.sendHTMLMail(comEmail,"KerryKidz 游乐园 预约通知",msg);
				 }
			}
		}
		HashMap<String,Object> putObj=new HashMap<String,Object>();
		
		putObj.put("OldpkOrderId", OldpkOrderId);
		putObj.put("pkParresId", pkParresId);
		putObj.put("orderPk",  orderPk);
		putObj.put("posOrderOld",  order);
		putObj.put("posOrderOldStatus",  order.getOrderStatus());
		putObj.put("zhucanPrice",zhucanPrice);
		return putObj;
	}
	
	 void addParResRoom(ParReserveEntity parReserve,String[] roomIds ){
			//===添加房间 预约关系 
			parReserveService.deleteParRoomByParId(parReserve.getPkParresId());//先删除老的 房间记录
		
			 for(String roomId:roomIds){
				ParReserveRoomEntity parReserveRoom =new ParReserveRoomEntity();
				parReserveRoom.setFkParresId(parReserve.getPkParresId());
				parReserveRoom.setFkRoomId(roomId);
				parReserveRoom.setLockFlag("0");//占用
				parReserveService.insertPReserveRoom(parReserveRoom);
			 }
			//====
	 }
	
	/**
	* @Title:  保存预约数据 到数据库 
	* @Description: <p>保存预约数据 到数据库 <p>
	* @date: 2014年8月6日
	* @return:  HashMap<String,Object>
	* @author chenyu
	* @throws 
	*
	 */
	@RequestMapping("/saveParReserve")
	@ResponseBody
	public  HashMap<String,Object> insertParReserve(HttpSession session,ParReserveEntity parReserve) throws Exception{
		String pkParresId =parReserve.getPkParresId();
		String abbrCode = UserUtil.getUserFromSession().getAbbrCode();// 门店缩写
		String branId = UserUtil.getUserFromSession().getBranId();// 门店编号
	
		
		parReserve.setResDay(DateUtil.getDate(parReserve.getPresDay()));
		parReserve.setModiTime(new Date());
		parReserve.setResStatus(Constants.RESERVE_STATUS_NOPREPAY);
		parReserve.setFkBranId(branId);
		HashMap<String,Object> putObj =null;
		 String[] roomIds =parReserve.getRoomIds().split(",");
		 String roomIdValue="";
		 for(int i=0;i<roomIds.length;i++){
			 if(i==roomIds.length-1){
				 roomIdValue+="'"+roomIds[i]+"'";
			 }else{
			   roomIdValue+="'"+roomIds[i]+"',";
			 }
		 }
		 parReserve.setRoomId(roomIdValue);
		 List<ParReserveRoomEntity> reserveRoomList=null;
			ParReserveEntity parReserveOld  =null;
			boolean copyHisFlag= false;
			double zhucanPriceOld=0;
			double oldPaidAmount=0;
			if(StringUtils.isBlank(pkParresId)){
				pkParresId = PrimaryKeyGenerator.getPrimaryKey(BusinessType.YY, abbrCode);
				parReserve.setPkParresId(pkParresId);
				parReserveService.insertParReserve(parReserve);
			}else{
			
				reserveRoomList=new ArrayList<ParReserveRoomEntity>();
				reserveRoomList= parReserveService.findParReserveRoomByparId(pkParresId);//老的 预约  房间 list
			    parReserveOld = parReserveService.findParReserveById(pkParresId);
				
				if(StringUtils.isNotBlank(parReserveOld.getBasicPkg())  ){
					String basicPkgs[] =parReserveOld.getBasicPkg().split("#");
					  zhucanPriceOld =parReserveService.findPrdPriceByPrdId(basicPkgs[0]);
					  oldPaidAmount =getpaidAmount(reserveRoomList,zhucanPriceOld);
				}
				String presDayNew =parReserve.getPresDay().trim();
				String presDayOld =DateUtil.formatDate("yyyy-MM-dd", parReserveOld.getResDay());
				//1. 派对更改（改日期，或加房间）时，并且修改的订单已预付（即当前状态=待确认），创建新订单复制原订单内容
				 if((!presDayNew.equals(presDayOld)|| roomIds.length>reserveRoomList.size()) && Constants.RESERVE_STATUS_TOBECONFIRM.equals(parReserveOld.getResStatus())){
					 pkParresId = PrimaryKeyGenerator.getPrimaryKey(BusinessType.YY, abbrCode);
					 parReserve.setFkPriorresId(parReserveOld.getPkParresId());//历史预约编号用于更改历史订单的保存
					 parReserve.setPkParresId(pkParresId);
					 if(!presDayNew.equals(presDayOld)){
						 Integer timecount= parReserveOld.getModiTimeCnt();
							if(null ==timecount){
								timecount =0;
							}
						 parReserve.setModiTimeCnt(parReserveOld.getModiTimeCnt()+1);
					 }
					 parReserve.setResStatus(Constants.RESERVE_STATUS_TOBECONFIRM);
						if(StringUtils.isBlank(parReserve.getSubject()) && StringUtils.isNotBlank(parReserveOld.getPkParresId())){
							parReserve.setSubject(parReserveOld.getSubject());
							parReserve.setFkPartypeId(parReserveOld.getFkPartypeId());
							parReserve.setChdName(parReserveOld.getChdName());
							parReserve.setFkMemId(parReserveOld.getFkMemId());
							parReserve.setConName(parReserveOld.getConName());
							parReserve.setConTel(parReserveOld.getConTel());
							parReserve.setConMobile(parReserveOld.getConMobile());
							parReserve.setConEmail(parReserveOld.getConEmail());
							parReserve.setOverTime(parReserveOld.getOverTime());
							parReserve.setComments(parReserveOld.getComments());
							parReserve.setSpecialist(parReserveOld.getSpecialist());
							parReserve.setWristColor(parReserveOld.getWristColor());
						}
					 parReserveService.insertParReserve(parReserve);
					 copyHisFlag =true;
				 }else{
				    parReserveService.updateParReserve(parReserve);
				 }
			}
			//===添加房间 预约关系 
			if(!copyHisFlag){
			 parReserveService.deleteParRoomByParId(parReserve.getPkParresId());//先删除老的 房间记录
			}
			 List<ParReserveRoomEntity> reserveRoomListNew=new ArrayList<ParReserveRoomEntity>();//新预定的房间list
			 List<ParRoomEntity> listRoom= parReserveService.findParRoom(branId);
			 for(String roomId:roomIds){
				ParReserveRoomEntity parReserveRoom =new ParReserveRoomEntity();
				parReserveRoom.setFkParresId(parReserve.getPkParresId());
				parReserveRoom.setFkRoomId(roomId);
				if(null !=listRoom){
					for(ParRoomEntity parRoom:listRoom){
						if(parRoom.getPkRoomId().equals(roomId)){
							parReserveRoom.setMaxCnt(parRoom.getMaxCnt());
							parReserveRoom.setMinCnt(parRoom.getMinCnt());
							break;
						}
					}
				}
				
				String lockFlag="1";//锁定
				if(null !=reserveRoomList){
					for(ParReserveRoomEntity peserveRoomOld:reserveRoomList){
						if(peserveRoomOld.getFkRoomId().equals(roomId.trim())){
							lockFlag="0";//占用
							break;
						}
					}
				}
				parReserveRoom.setLockFlag(lockFlag);
				reserveRoomListNew.add(parReserveRoom);
				if(null !=parReserveRoom){
					parReserveService.deleteParRoom(parReserveRoom);
				}
				parReserveService.insertPReserveRoom(parReserveRoom);
			 }
			//====
			 if(null !=parReserve && StringUtils.isNotBlank(parReserve.getBasicPkg())){
			  putObj=operateOrder(session,parReserve,"7",reserveRoomListNew,oldPaidAmount,copyHisFlag,parReserveOld);
			 }else{
				 putObj=new HashMap<String,Object>(); 
				 putObj.put("pkParresId", pkParresId);
				 putObj.put("orderPk", "");
			 }
		return putObj;
		
	}
	
	/**
	 *  根据 房间，套餐id 计算出 预付 金额
	 */
	public double getpaidAmount(List<ParReserveRoomEntity> parReserveRoomList,double zhucanPrice){
				double paidAmount=0;
				for(ParReserveRoomEntity parReserveRoom:parReserveRoomList){
					if(null!=parReserveRoom.getMinCnt()){
						int mincnt =parReserveRoom.getMinCnt();
						paidAmount +=mincnt*zhucanPrice;
					}
				}
				return paidAmount;
	}
	/**
	* @Title: 增加 附加套餐到数据库 
	* @Description: <p>增加 附加套餐到数据库  <p>
	* @date: 2014年8月6日
	* @return: String
	* @author chenyu
	* @throws 
	*
	 */
	@RequestMapping("/addParReserveFujia")
	@ResponseBody
	public HashMap<String,Object> addParReserveFujia(HttpSession session,ParReserveEntity parReserve,@RequestParam("addType") String addType) throws RDPException{
		String pkParresId =parReserve.getPkParresId();
		parReserve.setResDay(DateUtil.getDate(parReserve.getPresDay()));
		parReserve.setModiTime(new Date());
		parReserve.setResStatus(Constants.RESERVE_STATUS_NOPREPAY);
		String abbrCode = UserUtil.getUserFromSession().getAbbrCode();// 门店缩写
		String branId = UserUtil.getUserFromSession().getBranId();// 门店编号
		parReserve.setFkBranId(branId);
		 String[] roomIds =parReserve.getRoomIds().split(",");
		 String roomIdValue="";
		 for(int i=0;i<roomIds.length;i++){
			 if(i==roomIds.length-1){
				 roomIdValue+="'"+roomIds[i]+"'";
			 }else{
			   roomIdValue+="'"+roomIds[i]+"',";
			 }
		 }
		 if(StringUtils.isBlank(parReserve.getBasicPkg3())){
			 parReserve.setBasicPkg3(",");
		 }
		 if(StringUtils.isBlank(parReserve.getBasicPkg2())){
			 parReserve.setBasicPkg2(",");
		 }
		 parReserve.setRoomId(roomIdValue);
		if(StringUtils.isBlank(pkParresId)){
			pkParresId = PrimaryKeyGenerator.getPrimaryKey(BusinessType.YY, abbrCode);
			parReserve.setPkParresId(pkParresId);
			parReserveService.insertParReserve(parReserve);
		}else{
			parReserveService.updateParReserve(parReserve);
		}
		//===添加房间 预约关系 
		addParResRoom(parReserve,roomIds);
		//====
		HashMap<String,Object> gblprdMap =new HashMap<String,Object>();
		gblprdMap.put("pkParresId", pkParresId);
		gblprdMap.put("basicPkg2",  parReserve.getBasicPkg2());
		gblprdMap.put("basicPkg3",  parReserve.getBasicPkg3());
		return 	gblprdMap;
		
	}
	
	/**
	* @Title:根据房间编号，时间，查找是否 房间已经占用
	* @Description: <p>根据房间编号，时间，查找是否 房间已经占用<p>
	* @date: 2014年8月20日
	* @return: String
	* @author chenyu
	* @throws 
	*
	 */
	@RequestMapping("/findAlreadyRoomList")
	@ResponseBody
	public HashMap<String,Object> findAlreadyRoomList(@RequestParam("roomId") String roomId,@RequestParam("presDay") String presDay,
			@RequestParam("resTimeS") String resTimeS,@RequestParam("resTimeE") String resTimeE
			,@RequestParam("pkParresId") String pkParresId) throws RDPException{
		ParReserveEntity parReserve =new ParReserveEntity();
		
		parReserve.setPresDay(presDay.trim());
		parReserve.setResTimeS(resTimeS.trim());
		parReserve.setResTimeE(resTimeE.trim());
		 String[] roomIds =roomId.split(",");
		 String roomIdValue="";
		 for(int i=0;i<roomIds.length;i++){
			 if(i==roomIds.length-1){
				 roomIdValue+="'"+roomIds[i]+"'";
			 }else{
			   roomIdValue+="'"+roomIds[i]+"',";
			 }
		 }
		 parReserve.setRoomId(roomIdValue);
		 parReserve.setPkParresId(pkParresId);
		 List<ParReserveEntity> parReserveList=null;
		 HashMap<String,Object> gblprdMap =new HashMap<String,Object>();
		 ParReserveEntity parReserveNew = parReserveService.findParReserveById(pkParresId);
		 boolean iszhanyong =true;
		 if(null !=parReserveNew){
		  parReserveList= parReserveService.findAlreadyRoomList(parReserve);
		  if(null !=parReserveList && parReserveList.size()>0){
			  ParReserveEntity parReservdOld = parReserveList.get(0);
			  //老预约数据，和新预约 数据 有关联时 ，不弹出 房间 占用 的警告。
			  if(null !=parReservdOld && parReservdOld.getPkParresId().equals(parReserveNew.getFkPriorresId())){
				  iszhanyong =false;
			  }
		  }
		 }
		 if(iszhanyong){
		 gblprdMap.put("parReserveList",  parReserveList);
		 }else{
			 gblprdMap.put("parReserveList",  null);
		 }
		return 	gblprdMap;
		
	}
	
	/**
	 * add后，附加，  分页 列表
		 * @Description   
		 * GblScmPrdEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "addPageFujia", method = RequestMethod.POST)
	@ResponseBody
	public GblScmPrdEntity addPageFujia(GblScmPrdEntity scmprd,@RequestParam("addType") String addType) {
		String basicPkg="";
			basicPkg = scmprd.getBasicPkg2();
			List<GblScmPrdEntity> listUpdateScmTaocan = null;
		if(StringUtils.isNotBlank(basicPkg)){
		String[] productidArray =scmprd.getBasicPkg2().split(",");
		List<String> proIdList =new ArrayList<String>();
		HashMap<String,Integer> quantityMap =new HashMap<String,Integer>();
		for(int i=0;i<productidArray.length;i++){
			if(StringUtils.isBlank(productidArray[i])){
				continue;
			}else{
				String[] pids=productidArray[i].split("#");
		    	proIdList.add(pids[0]);
		    	int quantity =0;
		    	if(pids.length>1 && StringUtils.isNotBlank(pids[1])){
		    		quantity = Integer.parseInt(pids[1]);
		    	}
		    	quantityMap.put(pids[0], quantity);
			}
		}
		HashMap<String,Object> gblprdMap =new HashMap<String,Object>();
		if(null !=proIdList && proIdList.size()>0){
			gblprdMap.put("type", 1);//1 主食套餐
			gblprdMap.put("proIdList", proIdList);//附加  物品id
			scmprd.setParams(gblprdMap);
			if("pad".equals(scmprd.getDeviceType())){
				scmprd.setPageSize(4000);
			}else{
				scmprd.setPageSize(4);
			}
			  listUpdateScmTaocan = parReserveService.findScmRrdByprdIdListPage(scmprd);
				for(int k=0;k<listUpdateScmTaocan.size();k++){
					 String prdId=listUpdateScmTaocan.get(k).getPkPrdId();
								listUpdateScmTaocan.get(k).setQuantity(quantityMap.get(prdId));//设置 商品 的购买数量
				}
			} 
		}
		scmprd.setResults(listUpdateScmTaocan);
		return 	scmprd;
	}
	
	/**
	 * add后，  装饰 分页 列表
		 * @Description   
		 * GblScmPrdEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "addPageZhuangshi", method = RequestMethod.POST)
	@ResponseBody
	public GblScmPrdEntity addPageZhuangshi(GblScmPrdEntity scmprd,@RequestParam("addType") String addType) {
		String basicPkg="";
		List<GblScmPrdEntity> listUpdateScmTaocan =null;
			basicPkg = scmprd.getBasicPkg3();
		if(StringUtils.isNotBlank(basicPkg)){
		String[] productidArray =scmprd.getBasicPkg3().split(",");
		List<String> proIdList =new ArrayList<String>();
		HashMap<String,Integer> quantityMap =new HashMap<String,Integer>();
		for(int i=0;i<productidArray.length;i++){
			if(StringUtils.isNotBlank(productidArray[i])){
				String[] pids=productidArray[i].split("#");
		    	proIdList.add(pids[0]);
		    	int quantity =0;
		    	if(pids.length>1 && StringUtils.isNotBlank(pids[1])){
		    		quantity = Integer.parseInt(pids[1]);
		    	}
		    	quantityMap.put(pids[0], quantity);
			}
		}
		if(null !=proIdList && proIdList.size()>0){
			HashMap<String,Object> gblprdMap =new HashMap<String,Object>();
			gblprdMap.put("type", 1);//1 主食套餐
			gblprdMap.put("proIdList", proIdList);// 装饰 物品id
			scmprd.setParams(gblprdMap);
			if("pad".equals(scmprd.getDeviceType())){
				scmprd.setPageSize(4000);
			}else{
				scmprd.setPageSize(4);
			}
			
			 listUpdateScmTaocan = parReserveService.findScmRrdByprdIdListPage(scmprd);
				for(int k=0;k<listUpdateScmTaocan.size();k++){
					 String prdId=listUpdateScmTaocan.get(k).getPkPrdId();
						listUpdateScmTaocan.get(k).setQuantity(quantityMap.get(prdId));//设置 商品 的购买数量
				}
			}
		}
		scmprd.setResults(listUpdateScmTaocan);
		return 	scmprd;
	}
	/**
	* 团体预约 到下一步 预付页面  
	* @Description: <p>团体预约 到下一步 预付页面<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/saveNextParReserve")
	public ModelAndView saveNextParReserve(@RequestParam("deviceType") String deviceType,@RequestParam("pkParresId") String pkParresId,
			@RequestParam("orderPk") String orderPk,@RequestParam("parType") String parType,
			@RequestParam("OldpkOrderId") String OldpkOrderId,@RequestParam("zhucanPrice") String zhucanPrice) throws Exception{
		
		String guanliDetail="";
		if(StringUtils.isNotBlank(orderPk) && orderPk.indexOf("@")>0){//档案管理 --》派对，团体预约 详细页面 点击 过来的 ，订单Id
			String[] pkorderIds =orderPk.split("@");
			guanliDetail="guanliDetail";
			if(pkorderIds.length>1){
				orderPk = pkorderIds[1];
			}else{
				orderPk ="";
			}
		}
		
		String modelView="membership/order_x";
		if("pad".equals(deviceType)){
			modelView ="pad/ipad_mship/order_x";
		} 
		ModelAndView mav=new ModelAndView(modelView);
		List<GblPosDiscountEntity> discountList = productService.findAllDiscount();
		
		UserInfo user = UserUtil.getUserFromSession();
		String prdScopeok="";
		double camdisCount =0.0;// 促销打折率
			 

	
		
		String showDiscount="hiddendis";
		String disDesc ="";
		String disCount ="0.0";
		//=== 派对 优惠券 使用 判断
		ParReserveEntity parReserve = parReserveService.findParReserveById(pkParresId);
		if(null != parReserve && parReserve.getGrpFlag().equals("0")){
			String fkMemId=parReserve.getFkMemId();
			CusMemEntity cusMem = parReserveService.findSusMemByMemId(fkMemId);
				if(null != cusMem){
					GblScmPrdEntity product = new GblScmPrdEntity();
					product.setPkPrdId(cusMem.getMemberCardId());
					GblScmPrdEntity vip = parReserveService.findMemberProduct(product);
					if(null !=vip){
						int monthvip = vip.getMonth();
						PropertiesUtil prop = new PropertiesUtil();
						String distimes = prop.readSingleProps("PAR_NINEDTIMES", "/properties/kerrykidz.properties");
						int discishu =Integer.parseInt(distimes.trim());
						int countOrder =parReserveService.getCountMemOrderByMemId(fkMemId);
						if(monthvip<=6){//半年期会员卡，只能 使用一次 派对优惠券
							if(countOrder<discishu){
//								#派对优惠券折扣9折（半年期会员）
//								PAR_NINEDISDESC=9\u6298
//								PAR_NINEDISCOUNT=0.9
//
								showDiscount="showdis";
								
								disDesc = prop.readSingleProps("PAR_NINEDISDESC", "/properties/kerrykidz.properties");
								disCount = prop.readSingleProps("PAR_NINEDISCOUNT", "/properties/kerrykidz.properties");
							}
						}
						String dis2times = prop.readSingleProps("PAR_EIGHTTIMES", "/properties/kerrykidz.properties");
						int dis2cishu =Integer.parseInt(dis2times.trim());
						if(monthvip>=12){//1年期会员卡，只能 使用二次 派对优惠券
							if(countOrder<dis2cishu){
//								#派对优惠券折扣8折（1年期会员）
//								PAR_EIGHTDISDESC=8\u6298
//								PAR_EIGHTDISCOUNT=0.8
								showDiscount="showdis";
								  prop = new PropertiesUtil();
								  disDesc = prop.readSingleProps("PAR_EIGHTDISDESC", "/properties/kerrykidz.properties");
									disCount = prop.readSingleProps("PAR_EIGHTDISCOUNT", "/properties/kerrykidz.properties");
							}
						}
					}
				}
		}
		//===
		double paidAmount=0;
		double paidWuzheKou=0;
		double zPrice =Double.valueOf(zhucanPrice);
		List<ParReserveRoomEntity> parReserveRoomList=new ArrayList<ParReserveRoomEntity>();
		parReserveRoomList= parReserveService.findParReserveRoomByparId(pkParresId);
		for(ParReserveRoomEntity parReserveRoom:parReserveRoomList){
			if(null!=parReserveRoom.getMinCnt()){
				int mincnt =parReserveRoom.getMinCnt();
				paidAmount +=mincnt*zPrice;
			}
		}
		paidWuzheKou =paidAmount;
		List<PosOrderPrdEntity> listPosOrderPrd =new ArrayList<PosOrderPrdEntity>();
		int orderPrdSize =0;
		PosOrderEntity posOrder =orderService.findOrderByPk(orderPk); 
		double paymount =0.0;// 打折后，应付金额
		if(null !=posOrder){
			double disCo =Double.parseDouble(disCount);
			if(disCo>0 ){//&& StringUtils.isBlank(posOrder.getFkParcpnId())
			   paymount = posOrder.getAmount() * disCo;
			   paidAmount =paidAmount  * disCo;
			}else{
				showDiscount="hiddendis";
				paymount = posOrder.getAmount();
			}
			PosOrderPrdEntity posOrderPrd = new PosOrderPrdEntity();
			posOrderPrd.setPkOrderId(orderPk);
			 listPosOrderPrd = parReserveService.pageOrderPrdListByOrdId(user.getBranId(),orderPk); // 订单商品明细
			 orderPrdSize =listPosOrderPrd.size();
		} 
		double payMentMoney=0.0;// 已预付金额
		List<PosOrderPaymentEntity> orderPaymentList =iPaymentService.findByOrderPk(orderPk);
		if(null ==orderPaymentList || orderPaymentList.size()==0){
			orderPaymentList =iPaymentService.findByOrderPk(OldpkOrderId);
		}
		 if(null !=orderPaymentList && orderPaymentList.size()>0){
					 for(PosOrderPaymentEntity payment:orderPaymentList){
						 payMentMoney +=payment.getAmount();
					 }
					
					}
		 String payMentMoneys="";
		 if(payMentMoney>0){
			 payMentMoneys=String.valueOf(payMentMoney);
			 if(paidAmount>payMentMoney){
				 paidAmount =paidAmount-payMentMoney;//变更增加了房间，下单时，显示的预付金额 把上次预付的金额减掉
			 }
		 }
		  DecimalFormat df = new DecimalFormat("#.00");
		 mav.addObject("payMentMoney", payMentMoneys);
		mav.addObject("listPosOrderPrd", listPosOrderPrd);
		mav.addObject("orderPrdSize", orderPrdSize);
		mav.addObject("prdScopeok", prdScopeok);
		mav.addObject("camdisCount", camdisCount);
		mav.addObject("discountList", discountList);
		mav.addObject("orderPk", orderPk);
		mav.addObject("showDiscount", showDiscount);
		mav.addObject("TESHUdisCount", disCount); 
		mav.addObject("TESHUdisDesc", disDesc);
		mav.addObject("paidAmount", df.format(paidAmount));
		mav.addObject("paidWuzheKou", df.format(paidWuzheKou));
		mav.addObject("yingfuAmount", df.format(paymount));
		mav.addObject("guanliDetail", guanliDetail);
		mav.addObject("posOrderOld", posOrder);
		mav.addObject("parType", parType);
		mav.addObject("pkParresId", pkParresId);
		mav.addObject("zhucanPrice", zhucanPrice);
		return mav;
	}
	
	
	
	/**
	 * 初始化 附加菜单 分页 列表
		 * @Description   
		 * GblScmPrdEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "paginateFujia", method = RequestMethod.POST)
	@ResponseBody
	public GblScmPrdEntity paginateFujia(GblScmPrdEntity parReserve) {
		HashMap<String,Object> gblprdMap =new HashMap<String,Object>();
		gblprdMap.put("cateId1", Constants.RESERVE_PRDCATE_F_CODEFOOD);// 附加单点主食 冷
		gblprdMap.put("cateId2", Constants.RESERVE_PRDCATE_F_PEICAI);// 附加单点配菜
		gblprdMap.put("cateId3", Constants.PRDCATE_F_DESSERT);// 附加单点甜点
		gblprdMap.put("cateId4", Constants.PRDCATE_F_DRINK);//附加单点饮料 
		gblprdMap.put("parZhuShiCount", 1);
		parReserve.setParams(gblprdMap);
  
		List<GblScmPrdEntity> listGblScmFujia = parReserveService.findParReserveDandian(parReserve);//派对附加单菜单
		parReserve.setResults(listGblScmFujia);
		return parReserve;
	}
	
	/**
	 * 初始化 装饰 分页 列表
		 * @Description   
		 * GblScmPrdEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "paginateZhuangshi", method = RequestMethod.POST)
	@ResponseBody
	public GblScmPrdEntity paginateZhuangshi(GblScmPrdEntity parReserve) {
		HashMap<String,Object> 	gblprdMap =new HashMap<String,Object>();
		gblprdMap.put("cateId1", Constants.RESERVE_PRDCATE_QIQIU);//气球类
		gblprdMap.put("cateId2", Constants.RESERVE_PRDCATE_DINGZHI);// 相片定制类
		gblprdMap.put("cateId3", Constants.RESERVE_PRDCATE_CEGGS);// 彩蛋类
		gblprdMap.put("cateId4", Constants.PRDCATE_PERFORM);//表演类
		gblprdMap.put("parZhuShiCount", 1);
		parReserve.setParams(gblprdMap);
		List<GblScmPrdEntity> listGblTrimming = parReserveService.findParReserveTrimming(parReserve);//装饰
		parReserve.setResults(listGblTrimming);
		return parReserve;
	}
	

	
	/**
	 * 预付前，根据订单编号 查询 订单商品详细  分页 列表
		 * @Description   
		 * PosOrderPrdEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "pageOrderPrdListByOrdId", method = RequestMethod.POST)
	@ResponseBody
	public PosOrderPrdEntity pageOrderPrdListByOrdId(HttpSession session,PosOrderPrdEntity posOrderPrd) {
		UserInfo user = UserUtil.getUserFromSession();
		List<PosOrderPrdEntity> listPosOrderPrd = parReserveService.pageOrderPrdListByOrdId(user.getBranId(),posOrderPrd.getPkOrderId()); 
		posOrderPrd.setResults(listPosOrderPrd);
		return posOrderPrd;
	}
	
	/**
	 * 根据姓名或电话号码查询会员
		 * @Description   
		 * PosOrderPrdEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "pageQueryMemberList", method = RequestMethod.POST)
	@ResponseBody
	public CusMemEntity pageQueryMemberList(CusMemEntity cusMem) throws RDPException{
		cusMem.setPageSize(5);
		UserInfo user = UserUtil.getUserFromSession();
		String uBranId =user.getBranId();
		cusMem.setFkBranId(uBranId);
		List<CusMemEntity> listcusMem = parReserveService.findMemberByNameOrTel(cusMem); 
		cusMem.setResults(listcusMem);
		return cusMem;
	}
	
	/**
	 * 预付页面。点击 刷新 付款结果按钮
		 * @Description   
		 * PosOrderPrdEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "flashpayOk", method = RequestMethod.POST)
	@ResponseBody
	public String flashpayOk(@RequestParam("pkParresId") String pkParresId) throws RDPException{
		
		List<PosOrderEntity> posOrderList = parReserveService.findPosOrderByParresId(pkParresId);  
		String orderStatus="";
		if(null !=posOrderList && posOrderList.size()>0){
			PosOrderEntity posOrder =posOrderList.get(0);
			if(null !=posOrder){
				orderStatus =posOrder.getOrderStatus();
			}
		}
		return orderStatus;
	}
	//===========预约 管理
	
	/**
	* 初始化预约房间 列表  在 档案管理  --》预约管理列表，视图页面加载
	* @Description: <p>初始化预约房间 列表  在 档案管理  --》预约管理列表，视图页面加载<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/parReserveManages")
	public ModelAndView parReserveManages(ParReserveEntity parReserve,@RequestParam("indexflag") String indexflag) throws RDPException{
		ModelAndView mav=new ModelAndView("file/file_group");
		UserInfo user = UserUtil.getUserFromSession();
		String uBranId =user.getBranId();
		if("ZB".equals(user.getAbbrCode())){
			GblSecBranEntity secBranEntity = parReserveService.selectBranByAbbrCode("WX");
			if(null != secBranEntity){
				uBranId =secBranEntity.getPkBranId();
			}
		}
		List<ParRoomEntity> listRoom= parReserveService.findParRoom(uBranId);
		List<SecUsrEntity> listuserPar =new ArrayList<SecUsrEntity>();
		listuserPar =getlistuserPar(user);
		mav.addObject("listRoom", listRoom);
		mav.addObject("indexflag", indexflag);
		mav.addObject("listuserPar", listuserPar);
		mav.addObject("userIddq", user.getUserId());
		mav.addObject("branIddq", uBranId);
		mav.addObject("dateNow", DateUtil.formatDate("yyyy-MM-dd",new Date()));
		return mav;
	}
	 
	public List<SecUsrEntity> getlistuserPar(UserInfo user){
		String uBranId =user.getBranId();
		List<SecUsrEntity> listuserPar =new ArrayList<SecUsrEntity>();
		List<String> roleList = user.getRoleList();
		if (null!=roleList && (roleList.get(0).equals("106") || roleList.get(0).equals("109"))) {// && roleList.size()==1
			SecUsrEntity secEntity =new SecUsrEntity();
			secEntity.setUsrName(user.getName());
			secEntity.setPkUsrId(user.getUserId());
			listuserPar.add(secEntity);
		}else{
			listuserPar =parReserveService.listUserByRoleId("109",uBranId);//派对团体专员
		}
		return listuserPar;
	}
	/**
	* @Title:  查询 预约房间列表，在 日历控件 模式中显示  
	* @Description: <p>查询 预约房间列表，在 日历控件 模式中显示  <p>
	* @date: 2014年8月11日
	* @return: List<ParReserveEntity>
	* @throws 
	 */
	@RequestMapping("/findParReserveRooMList")
	@ResponseBody
	public  HashMap<String,Object> findParReserveRooMList(ParReserveEntity parReserve) throws Exception{
		HashMap<String,Object> 	gblparResRoomMap =new HashMap<String,Object>();
		List<ParReserveEntity> parResRoomList =parReserveService.findParReserveRooMListView(parReserve);
		List<String> parResDateList =parReserveService.findParReserveDateRooM(parReserve);
		gblparResRoomMap.put("gblparResRoomMap", parResRoomList);
		gblparResRoomMap.put("parResDateList", parResDateList);
		return gblparResRoomMap;
	}
	/**
	 * 初始化预约房间 列表  在 档案管理 --》预约管理  分页列表 中显示
		 * @Description   
		 * GblScmPrdEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "parReservePageListManages", method = RequestMethod.POST)
	@ResponseBody
	public ParReserveEntity parReservePageListManages(ParReserveEntity parReserve) {
		List<ParReserveEntity> parResRoomPageList =parReserveService.parReservePageListManages(parReserve);
		parReserve.setResults(parResRoomPageList);
		return parReserve;
	}
	
	/**
	* 初始化预约房间 列表  在 档案管理  --》预约管理详细页面加载
	* @Description: <p>初始化预约房间 列表  在 档案管理  --》预约管理详细页面加载<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/parReserveManagesDetail")
	public ModelAndView parReserveManagesDetail(@RequestParam("pkParresId") String pkParresId,
			@RequestParam("grpFlag") String parType,HttpSession session) throws RDPException{
		
		List<ParCTypeEntity> cTypeList= new ArrayList<ParCTypeEntity>();
		String modelView="file/file_liet_t";
		if(parType.equals("0")){// =0 派对
			 cTypeList= parReserveService.findParCtypeList();
			 modelView= "file/file_liet";
		}
		PosOrderEntity posOrder =null;
		List<PosOrderEntity> posOrderList =parReserveService.findPosOrderByParresId(pkParresId);
		if(null !=posOrderList && posOrderList.size()>0){
			posOrder =posOrderList.get(0);
		}
		String basicPkg="";
		double zhucanPrice=0;
		UserInfo user = UserUtil.getUserFromSession();
		String zhuanBrandId =user.getBranId();
		ParReserveEntity parreserve=null;
		String specialist ="";//派对专员
		String wristColorId ="";//腕带颜色
		 PosOrderEntity oldPosorder =null;
		ModelAndView mav=new ModelAndView(modelView);
		String fkContactFile = null;
		String fkSignFile = null;
		String pkOrderId="";
		String OldpkOrderId="";
		String oldFkPriorresId="";
		if(null !=posOrder){
			pkOrderId = posOrder.getPkOrderId();
		}
		String presDay =null;
		String resTimeS=null;String resTimeE=null;
		if(StringUtils.isNotBlank(pkParresId)){
			parreserve=parReserveService.findParReserveById(pkParresId);
			if(null!=parreserve){
			presDay =DateUtil.formatDate("yyyy-MM-dd", parreserve.getResDay());
			resTimeS =parreserve.getResTimeS(); resTimeE =parreserve.getResTimeE();
			  fkContactFile = parreserve.getFkContactFile();
			  fkSignFile = parreserve.getFkSignFile();
			  oldFkPriorresId =parreserve.getFkPriorresId();
			  if(StringUtils.isNotBlank(oldFkPriorresId)){//历史预约编号用于查询 历史订单 
				   posOrderList =parReserveService.findPosOrderByParresId(oldFkPriorresId);
				  if(null !=posOrderList && posOrderList.size()>0){
					  oldPosorder =posOrderList.get(0);
				  }
				  if(null !=oldPosorder){
					  OldpkOrderId =oldPosorder.getPkOrderId();
				  }
			  }
			  if(StringUtils.isNotBlank( parreserve.getSpecialist())){
			   specialist = parreserve.getSpecialist();
			  }
			  if(StringUtils.isNotBlank(parreserve.getWristColor())){
				  wristColorId = parreserve.getWristColor();
			  }
			  parreserve.setPresDay(DateUtil.formatDate("yyyy-MM-dd", parreserve.getResDay()));
			  parreserve.setPmodiTime(DateUtil.formatDate("yyyy-MM-dd HH:mm:ss", parreserve.getModiTime()));
			  basicPkg =parreserve.getBasicPkg();
			  String basicPkgs[] =basicPkg.split("#");
			  zhucanPrice =parReserveService.findPrdPriceByPrdId(basicPkgs[0]);
			  zhuanBrandId =parreserve.getFkBranId();
			}
		}
		List<SecUsrEntity> listuserPar =parReserveService.listUserByRoleId("109",zhuanBrandId);//派对团体专员
		List<GblParCWricorEntity> gblParCWricorList =parReserveService.findParWricorList();
		HashMap<String,Object> sysCodeMap =new HashMap<String,Object>();
		if(null !=presDay && null !=resTimeS && null !=resTimeE){
			sysCodeMap.put("presDay", presDay);	sysCodeMap.put("resTimeS", resTimeS);	sysCodeMap.put("resTimeE", resTimeE);
			List<String> codeList =parReserveService.findWristColorByresDate(sysCodeMap);
			if(null !=codeList && codeList.size()>0){
				if(null !=gblParCWricorList && gblParCWricorList.size()>0){ 
					for (int i = 0; i < gblParCWricorList.size(); i++) {
						String pwrId=gblParCWricorList.get(i).getPkWricorId();
						for(int j=0;j<codeList.size();j++){
							 if (codeList.get(j).equals(pwrId)) {
								 gblParCWricorList.remove(i);
								 i=i-1;//每移除一个元素以后再把i移回来
								 break;
							 }
						}
						}

			}
			}
		}
		List<ParReserveRoomEntity> listparRoom= parReserveService.findParReserveRoomByparId(pkParresId);
		String rooms="";
		int i=1;
		for(ParReserveRoomEntity parRoom:listparRoom){
			rooms +=i+":"+parRoom.getRoomName()+" ";
		}
		
		parreserve.setRoomIds(rooms);
	 
		mav.addObject("zbBranid", UserUtil.getUserFromSession().getBranId()); 
		mav.addObject("listuserPar", listuserPar); 
		mav.addObject("pkParresId", pkParresId);
		mav.addObject("pkOrderId", pkOrderId);mav.addObject("OldpkOrderId", OldpkOrderId);
		mav.addObject("cTypeList", cTypeList);
		mav.addObject("parreserveOld", parreserve);
		mav.addObject("parType", parType); 
		mav.addObject("specialist", specialist); 
		mav.addObject("wristColor", wristColorId); 
		mav.addObject("gblParCWricorList", gblParCWricorList); 
		mav.addObject("zhucanPrice", zhucanPrice); 
		mav.addObject("fkSignFile",fkSignFile);
		mav.addObject("fkContactFile",fkContactFile);
		mav.addObject("keySignFile", Constants.SYS_BASE_PATH_TSIGN);
		mav.addObject("keyContactFile", Constants.SYS_BASE_PATH_CONT);
			return loadDataList( mav, parType,basicPkg,session,parreserve);
	}
	
	/**
	 * 经理 对 订单商品设置 折扣价格
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/orderPrdDiscount")
	@ResponseBody
	public String orderPrdDiscount(HttpSession session, @RequestParam(value="prdId")String prdId
			, @RequestParam(value="pkOrderId") String pkOrderId, @RequestParam(value="selDis") String selDis
			,@RequestParam(value="fkUserId") String fkUserId) throws Exception {
		PosOrderPrdEntity  posOrderPrd =new PosOrderPrdEntity();
		posOrderPrd.setPkOrderId(pkOrderId);
		posOrderPrd.setFkPrdId(prdId);
		posOrderPrd= parReserveService.orderPrdByOrdIdAndPrdId(pkOrderId,prdId);
		PosOrderEntity posOrderEntity =orderService.findOrderByPk(pkOrderId); 
		String seldiscount ="";
		String msg ="";
		double disprice= 0.0;
		if(null !=posOrderPrd){
			String[] seldisArray =selDis.split("_");
			seldiscount =seldisArray[1];
			 disprice=Double.valueOf(seldiscount) * posOrderPrd.getPrice() ;
				double dispAmount = disprice*posOrderPrd.getCount();//折后金额
			posOrderPrd.setDisPrice(dispAmount);
			posOrderPrd.setFkDisId(seldisArray[0]);
			posOrderPrd.setFkDisusrId(fkUserId);
		 orderService.updateOrderProduct(posOrderPrd);
		 double paidAmount =posOrderEntity.getPaidAmount();
		 msg = dispAmount+"@@"+seldiscount+"@@"+paidAmount;
		}
		 
		return msg;
	}
	
	
	/**
	 * 经理 对 订单商品设置整单  折扣价格
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/orderAllPrdDiscount")
	@ResponseBody
	public HashMap<String,Object> orderAllPrdDiscount(HttpSession session, @RequestParam(value="prdId")String prdId
			, @RequestParam(value="pkOrderId") String pkOrderId, @RequestParam(value="selDis") String selDis
			,@RequestParam(value="fkUserId") String fkUserId) throws Exception {
		if(StringUtils.isNotBlank(prdId)){
			String[] prdids =prdId.split(",");
			for(int i=0;i<prdids.length;i++){
				String[] ordPrdIds =prdids[i].split("@");
				if(ordPrdIds[1].equals("1")){//1 表示 除装饰物之外的所有商品
					//================
					PosOrderPrdEntity  posOrderPrd =new PosOrderPrdEntity();
					posOrderPrd.setPkOrderId(pkOrderId);
					posOrderPrd.setFkPrdId(ordPrdIds[0]);
					posOrderPrd= parReserveService.orderPrdByOrdIdAndPrdId(pkOrderId,ordPrdIds[0]);
					String seldiscount ="";
				
					double disprice= 0.0;
					if(null !=posOrderPrd){
						String[] seldisArray =selDis.split("_");
						seldiscount =seldisArray[1];
					
						 disprice=Double.valueOf(seldiscount) * posOrderPrd.getPrice() ;
							double dispAmount = disprice*posOrderPrd.getCount();//折后金额
						posOrderPrd.setDisPrice(dispAmount);
						posOrderPrd.setFkDisId(seldisArray[0]);
						posOrderPrd.setFkDisusrId(fkUserId);
					 orderService.updateOrderProduct(posOrderPrd);
					}
				}
			}
		}
		PosOrderEntity posOrderEntity =orderService.findOrderByPk(pkOrderId); 
		List<PosOrderPrdEntity> posOrderPrdList = orderService.findOrderPrdByOrderId(pkOrderId);
		HashMap<String,Object> prdListMap =new HashMap<String,Object>();
		prdListMap.put("posOrderPrdList", posOrderPrdList);
		prdListMap.put("paidAmount", posOrderEntity.getPaidAmount());
		return prdListMap;
	}
	
	/**
	 * 在 预约管理 详细 页面 。点击 最终确认 按钮。继续确认 预约。
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/managerDetailAffirm")
	@ResponseBody
	public String managerDetailAffirm(HttpSession session, @RequestParam(value="parType")String parType
			, @RequestParam(value="pkParresId") String pkParresId, @RequestParam(value="pkorderId") String pkorderId) throws Exception {
		List<PosOrderEntity> posOrderList =parReserveService.findPosOrderByParresId(pkParresId);
		String msg="";
		ParReserveEntity parReserve=parReserveService.findParReserveById(pkParresId);
		
		if(null !=posOrderList && posOrderList.size()>0){
			PosOrderEntity posOrder =posOrderList.get(0);
		if(null !=posOrder){
			if(null !=parReserve){
//				String resStatus =parReserve.getResStatus();
			String posOrderStatus =posOrder.getOrderStatus();
			//resStatus.equals(Constants.RESERVE_STATUS_TOBECONFIRM) && (
			if(posOrderStatus.equals(ORDER_CONSTANTS.ORDER_STATUS_HAS_BEEN_PAY) || posOrderStatus.equals("6")){//6 已预付
					parReserve.setModiBy(UserUtil.getUserFromSession().getUserId());
					parReserve.setModiTime(new Date());
					parReserve.setResStatus(Constants.RESERVE_STATUS_CONFIRMED);
					parReserveService.updateParReserve(parReserve);
					msg="1";
				}else{
					msg="2";//系统错误，获取预约数据失败。
				}
			}else{
				msg="3";//此预约 未预付金额。请先预付金额，再最终确定操作。
			}
		}else{
			msg="4";//系统错误，获取订单数据失败。
		}
		}else{
			msg="4";//系统错误，获取订单数据失败。
		}
		return msg;
	}
	
 
	
	/**
	 *  查找可用的 条码列表
		 * @Description   
		 * SysBarCodeEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "findSysBarCodeList", method = RequestMethod.POST)
	@ResponseBody
	public SysBarCodeEntity findSysBarCodeList(HttpSession session,SysBarCodeEntity sysBarCode) throws RDPException{
//		sysBarCode.setPageSize(10);
		sysBarCode.setFkBranId(UserUtil.getUserFromSession().getBranId());
		List<SysBarCodeEntity> sysBarCodeList = parReserveService.findSysBarCodeList(sysBarCode); 
		sysBarCode.setResults(sysBarCodeList);
		return sysBarCode;
	}
	
	
	/**
	 * 成员 条码生成 时，插入到 派对出入场表。
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/saveLocParTyInOut")
	@ResponseBody
	public String saveLocParTyInOut(HttpSession session 
			, @RequestParam(value="pkParresId") String pkParresId,
			@RequestParam(value="pkBcodeId") String pkBcodeId,@RequestParam(value="type") String type) throws Exception {
	    LocPartyInoutEntity localPartyInout=new LocPartyInoutEntity();
		     
		    UserInfo user= UserUtil.getUserFromSession();
		    localPartyInout.setFkParresId(pkParresId);
		    localPartyInout.setFkBranId(user.getBranId());
		    localPartyInout.setFkBcodeId(pkBcodeId);
	    List<LocPartyInoutEntity> localPartyInoutOldList= parReserveService.findLocParTyInOut(localPartyInout);
		String msg="1";
		SysBarCodeEntity barCodeEntity =new SysBarCodeEntity();
		barCodeEntity.setPkBcodeId(pkBcodeId);
		
		if(null ==localPartyInoutOldList ||localPartyInoutOldList.size()==0){
			String abbrCode = user.getAbbrCode();// 门店缩写
			localPartyInout.setPkPartyIoId(PrimaryKeyGenerator.getPrimaryKey(BusinessType.PA, abbrCode));
			localPartyInout.setOperateBy(user.getUserId());  
			parReserveService.addLocParTyInOut(localPartyInout);
			
			barCodeEntity.setStatus("1");//（条码是否被占用的标记=1 占用，=0 未占用）
			iSysBarCodeService.updateBcodeStatus(barCodeEntity);
		}else{
			if(type.equals("cancel")){
						parReserveService.deleteLocParTyInOutById(localPartyInoutOldList.get(0));
						barCodeEntity.setStatus("0");//（条码是否被占用的标记=1 占用，=0 未占用）
						iSysBarCodeService.updateBcodeStatus(barCodeEntity);
			}
		}
		return msg;
	}
	
	
	/**
	 * 全选，全部取消 成员 条码 生成 时，插入到 派对出入场表。
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/saveAllLocParTyInOut")
	@ResponseBody
	public String saveAllLocParTyInOut(HttpSession session 
			, @RequestParam(value="pkParresId") String pkParresId,
			@RequestParam(value="pkBcodeIds") String pkBcodeIds,@RequestParam(value="type") String type) throws Exception {
	    LocPartyInoutEntity localPartyInout=new LocPartyInoutEntity();
	    String msg="1";
	       if(StringUtils.isNotBlank(pkBcodeIds)){
	    	 parReserveService.deleteLocParTyInOutByParresId(pkParresId);//先批量删除  派对出入场表的 条形码
	         String[] pkBcodeIdArray =pkBcodeIds.split(",");
	         for(String pkBcodeId:pkBcodeIdArray){
			    UserInfo user= UserUtil.getUserFromSession();
			    localPartyInout.setFkParresId(pkParresId);
			    localPartyInout.setFkBranId(user.getBranId());
			    localPartyInout.setFkBcodeId(pkBcodeId);
				SysBarCodeEntity barCodeEntity =new SysBarCodeEntity();
				barCodeEntity.setPkBcodeId(pkBcodeId);
				if(type.equals("add")){
					String abbrCode = user.getAbbrCode();// 门店缩写
					localPartyInout.setPkPartyIoId(PrimaryKeyGenerator.getPrimaryKey(BusinessType.PA, abbrCode));
					localPartyInout.setOperateBy(user.getUserId());  
					parReserveService.addLocParTyInOut(localPartyInout);
					barCodeEntity.setStatus("1");//（条码是否被占用的标记=1 占用，=0 未占用）
					iSysBarCodeService.updateBcodeStatus(barCodeEntity);
				}
				else if(type.equals("cancel")){
								barCodeEntity.setStatus("0");//（条码是否被占用的标记=1 占用，=0 未占用）
								iSysBarCodeService.updateBcodeStatus(barCodeEntity);
				}
	         }
	       } 
	   
		

		return msg;
	}
	/**
	 * 派对 预约时 保存腕带颜色。
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/saveWristColor")
	@ResponseBody
	public String saveWristColor(HttpSession session 
			, @RequestParam(value="wristColor") String wristColor,
			@RequestParam(value="specialist") String specialist,@RequestParam(value="pkParresId") String pkParresId) throws Exception {
		ParReserveEntity parReserve=parReserveService.findParReserveById(pkParresId);
		String msg="1";
		if(null !=parReserve){
			parReserve.setModiBy(UserUtil.getUserFromSession().getUserId());
			parReserve.setSpecialist(specialist);
			parReserve.setModiTime(new Date());
			parReserve.setWristColor(wristColor);
			parReserveService.updateParReserve(parReserve);
		}else{
			msg="2";//系统错误，保存腕带颜色失败。
		}
		
		return msg;
	}
	
	// 出入场
	/**
	* @Title:出入场 派对 日历控件
	* @Description: <p>出入场 派对 日历控件<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/inOutManagementPar")
	public ModelAndView inOutManagementPar(@RequestParam(value="type") String type,HttpSession session){
		ModelAndView mav=new ModelAndView("management/management_tuan");
		UserInfo user= UserUtil.getUserFromSession();
		String uBranId =user.getBranId();
		if("ZB".equals(user.getAbbrCode())){
			GblSecBranEntity secBranEntity = parReserveService.selectBranByAbbrCode("WX");
			if(null != secBranEntity){
				uBranId =secBranEntity.getPkBranId();
			}
		}
		List<SecUsrEntity> listuserPar =parReserveService.listUserByRoleId("109",uBranId);//派对团体专员
		List<ParRoomEntity> listRoom= parReserveService.findParRoom(uBranId);
		mav.addObject("listRoom", listRoom);
		mav.addObject("type", type);
		mav.addObject("listuserPar", listuserPar);
		mav.addObject("dateNow", DateUtil.formatDate("yyyy-MM-dd",new Date()));
		return mav;
	}
	
	/**
	 * @throws Exception 
	* @Title:入场 派对 详细页面 条形码 扫描 确认
	* @Description: <p>入场 派对 详细页面 条形码 扫描 确认<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/inManagementParReg")
	public ModelAndView inManagementParReg(HttpSession session 
			, @RequestParam(value="pkParresId") String pkParresId,@RequestParam(value="grpFlag") String grpFlag,@RequestParam(value="type") String type) throws Exception{
		String modeView ="management/management_reg";
		String grpName="派对";
		if(grpFlag.equals("1")){
			modeView ="management/management_tun";
			grpName="团体";
		}
		String wristColor="";
		String wristColorId="";
		ModelAndView mav=new ModelAndView(modeView);
		ParReserveEntity parReserve=parReserveService.findParReserveById(pkParresId);
		//判断是否已确认
		if(null!=parReserve && null!=parReserve.getResStatus()){
			String resStatus=parReserve.getResStatus();
			if(null!=resStatus && !"5".equals(resStatus) && !"6".equals(resStatus)){
				throw new Exception("确认后的"+grpName+"才能进场!");
			}
			
			//判断是否非预约内时间
			String resTimeS=parReserve.getResTimeS();
			String resTimeE=parReserve.getResTimeE();
			String nowHM=DateUtil.formatDate("HHmm", new Date());
			//派对团体可提前半小时进入
			Date nowDateAddHalf=DateUtil.addMinute2Date(30, new Date());
			String nowHMAddHalf=DateUtil.formatDate("HHmm", nowDateAddHalf);
			/*Date nowHMDate=DateUtil.getDate(nowHM, "HHmm");
			Date resTimeSDate=DateUtil.getDate(resTimeS, "HHmm");
			Date resTimeEDate=DateUtil.getDate(resTimeE, "HHmm");
			if(DateUtil.getDiffSeconds(nowHMDate, resTimeSDate)<0l || DateUtil.getDiffSeconds(nowHMDate, resTimeEDate)>=0l){
				mav.addObject("isValid","yes");//非派对时间内进场标志
			}*/
			int resTimeSInt=0;
			int resTimeEInt=0;
			int nowHMInt=0;
			int nowHMAddHalfInt=0;
			if(null!=resTimeS && !"".equals(resTimeS)){
				resTimeSInt=Integer.parseInt(resTimeS);
			}
			if(null!=resTimeE && !"".equals(resTimeE)){
				resTimeEInt=Integer.parseInt(resTimeE);
			}
			if(null!=nowHM && !"".equals(nowHM)){
				nowHMInt=Integer.parseInt(nowHM);
			}
			if(null!=nowHMAddHalf && !"".equals(nowHMAddHalf)){
				nowHMAddHalfInt=Integer.parseInt(nowHMAddHalf);
			}
			if(nowHMAddHalfInt<resTimeSInt){
				mav.addObject("isValid","yes");//非派对时间内进场标志
			}else if(nowHMInt>=resTimeEInt){
				mav.addObject("overValid","yes");//非派对时间内进场标志
			}
		}else{
			throw new Exception("pkParresId不能为空!");
		}
		
		 SecUsrEntity zhuanyuanUser =null;
		 boolean isTaocan=true;//默认   是 提供餐饮
		if(null !=parReserve){
			List<ParReserveRoomEntity> listparRoom= parReserveService.findParReserveRoomByparId(parReserve.getPkParresId());
			String rooms="";
			int i=1;
			for(ParReserveRoomEntity parRoom:listparRoom){
				rooms +=i+":"+parRoom.getRoomName()+" ";
			}
			
			
			if(grpFlag.equals("1") && parReserve.getBasicPkg().startsWith(Constants.RESERVE_PRDCATE_4NOMEAL)){
				isTaocan= false;//（不含餐）SP1408070540
			}
			String resTimeS =parReserve.getResTimeS();
			String resTimeE = parReserve.getResTimeE();
			wristColorId=parReserve.getWristColor();
			wristColor=parReserve.getWristColor();
			if(StringUtils.isNotBlank(wristColor)){
				GblParCWricorEntity gblParCWricor  =parReserveService.findParWricorById(wristColor);
				wristColor = gblParCWricor.getWricorDesc();
			  }
			String showresTime =resTimeS.substring(0,2)+":"+resTimeS.substring(2,4)+"~"+resTimeE.substring(0,2)+":"+resTimeE.substring(2,4);
			parReserve.setRoomIds(rooms);
			parReserve.setPresDay( DateUtil.formatDate("yyyy-MM-dd",parReserve.getResDay()));
			parReserve.setResTimeS(showresTime);
			      zhuanyuanUser =userService.findEntityById(parReserve.getSpecialist());
		}
		mav.addObject("parreserveOld",parReserve);
		mav.addObject("zhuanyuanUser",zhuanyuanUser);
		mav.addObject("isTaocan",isTaocan);
		mav.addObject("wristColor",wristColor);
		mav.addObject("wristColorId",wristColorId);
		mav.addObject("dateNow", DateUtil.formatDate("yyyy-MM-dd",new Date()));
		mav.addObject("type",type);//记录表头选中
		return mav;
		
	}
	
	
	/**
	* @Title:出场 派对 详细页面 条形码 扫描 确认
	* @Description: <p>入场 派对 详细页面 条形码 扫描 确认<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/outManagementParReg")
	public ModelAndView outManagementParReg(HttpSession session 
			, @RequestParam(value="pkParresId") String pkParresId,@RequestParam(value="grpFlag") String grpFlag,@RequestParam(value="type") String type) throws RDPException{
		String modeView ="management/management_reg_x";
		if(grpFlag.equals("1")){
			modeView ="management/management_tun_x";
		}
		String wristColor="";
		String wristColorId="";
		ModelAndView mav=new ModelAndView(modeView);
		ParReserveEntity parReserve=parReserveService.findParReserveById(pkParresId);
		 SecUsrEntity zhuanyuanUser =null;
		 boolean isTaocan=true;//默认   是 提供餐饮
		if(null !=parReserve){
			List<ParReserveRoomEntity> listparRoom= parReserveService.findParReserveRoomByparId(parReserve.getPkParresId());
			String rooms="";
			int i=1;
			for(ParReserveRoomEntity parRoom:listparRoom){
				rooms +=i+":"+parRoom.getRoomName()+" ";
			}
			
			
			if(grpFlag.equals("1") && parReserve.getBasicPkg().startsWith(Constants.RESERVE_PRDCATE_4NOMEAL)){
				isTaocan= false;//（不含餐）SP1408070540
			}
			String resTimeS =parReserve.getResTimeS();
			String resTimeE = parReserve.getResTimeE();
			 wristColor=parReserve.getWristColor();
			 wristColorId=parReserve.getWristColor();
			if(StringUtils.isNotBlank(wristColor)){
				GblParCWricorEntity gblParCWricor  =parReserveService.findParWricorById(wristColor);
				wristColor = gblParCWricor.getWricorDesc();
			  }
			String showresTime =resTimeS.substring(0,2)+":"+resTimeS.substring(2,4)+"~"+resTimeE.substring(0,2)+":"+resTimeE.substring(2,4);
			parReserve.setRoomIds(rooms);
			parReserve.setPresDay( DateUtil.formatDate("yyyy-MM-dd",parReserve.getResDay()));
			parReserve.setResTimeS(showresTime);
			zhuanyuanUser =userService.findEntityById(parReserve.getSpecialist());
		}
		mav.addObject("parreserveOld",parReserve);
		mav.addObject("zhuanyuanUser",zhuanyuanUser);
		mav.addObject("isTaocan",isTaocan);
		mav.addObject("wristColor",wristColor);
		mav.addObject("wristColorId",wristColorId);
		mav.addObject("dateNow", DateUtil.formatDate("yyyy-MM-dd",new Date()));
		mav.addObject("type",type);//记录表头选中
		return mav;
		
	}
	/**
	 *  查找派对在入场 表  已生成好的  条码 分页列表
		 * @Description   
		 * LocPartyInoutEntity
		 * @author chenyu
		 * 2014年8月12日 下午2:56:13
	 */
	@RequestMapping(value = "localPartyInCodeList", method = RequestMethod.POST)
	@ResponseBody
	public LocPartyInoutEntity localPartyInCodeList(HttpSession session,LocPartyInoutEntity localPartyInout) throws RDPException{//, MyBatisSuperModel model
		localPartyInout.setFkBranId(UserUtil.getUserFromSession().getBranId());
		//Map<String, Object> paramMap = new HashMap<String, Object>();
		//paramMap.put(Constants.BARCODE_FKPAR, localPartyInout.getFkParresId());
		//paramMap.put(Constants.BARCODE_FKBRANID, localPartyInout.getFkBranId());
		//model.setParams(paramMap);
	    //List<LocPartyInoutEntity> localPartyInoutList= parReserveService.findLocParTyInListByPage(model);//分页
		List<LocPartyInoutEntity> localPartyInoutList= parReserveService.localPartyInCodeList(localPartyInout);
	    
		 if(null!=localPartyInoutList && localPartyInoutList.size()>0){
				//更新条码状态
				try {
					for (int i = 0; i < localPartyInoutList.size(); i++) {
						LocPartyInoutEntity locPartyInout=localPartyInoutList.get(i);
						locPartyInout.setIsOut(true);
						String parReserveId=locPartyInout.getFkParresId();
						ParReserveEntity parReserve=parReserveService.findParReserveById(parReserveId);
						Date resDay=parReserve.getResDay();//预约 日期
						String resTimeEnd=parReserve.getResTimeE();
						//派对结束超过30分钟后要求出场的客人，提示“派对超时30分钟，请补单次票。”，“出场”按钮禁用
						//当前日期-30分钟比结束日期大，成立
						if(null!=resDay && null!=resTimeEnd){
							String resDay2=DateUtil.formatDate("yyyy-MM-dd", resDay);
							String endTime=resDay2+" "+resTimeEnd.substring(0,2)+":"+resTimeEnd.substring(2,4)+":00";
							Long seconds=DateUtil.getDiffSeconds(DateUtil.addMinute2Date(-30, new Date()), DateUtil.getDate(endTime, "yyyy-MM-dd HH:mm:ss"));
							if(seconds<0l){
								locPartyInout.setIsOut(false);
							}
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
	    localPartyInout.setResults(localPartyInoutList);
	    //model.setResults(localPartyInoutList);
		return localPartyInout;
	}
	
	/**
	 * 派对 进场时 扫描条形码 更新入场 时间/出场时间。
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/updatelocalPartyCodeInOutTime")
	@ResponseBody
	public String updatelocalPartyCodeInOutTime(HttpSession session 
			, @RequestParam(value="pkBcodeId") String pkBcodeId,
			@RequestParam(value="guaCount") String guaCount,@RequestParam(value="pkParresId") String pkParresId,@RequestParam(value="type") String type) throws Exception {
		 LocPartyInoutEntity localPartyInout=new LocPartyInoutEntity();
	     
		    UserInfo user= UserUtil.getUserFromSession();
		    localPartyInout.setFkParresId(pkParresId);
		    localPartyInout.setFkBranId(user.getBranId());
		    localPartyInout.setFkBcodeId(pkBcodeId);//barcode
	    List<LocPartyInoutEntity> localPartyInoutOldList= parReserveService.findLocParTyInOut(localPartyInout);
		String msg="1";
		if(null !=localPartyInoutOldList && localPartyInoutOldList.size()>0){
			SysBarCodeEntity entitySysBarCode =new SysBarCodeEntity();
			entitySysBarCode.setBarCode(pkBcodeId);
			entitySysBarCode.setFkBranId(UserUtil.getUserFromSession().getBranId());
			List<SysBarCodeEntity> sysBarCodeList = parReserveService.selectSBarCodeBrandId(entitySysBarCode);
			String bcodeId = null;
			String status = null;
			if(null!=sysBarCodeList && sysBarCodeList.size()>0 && null!=sysBarCodeList.get(0)){
				bcodeId = sysBarCodeList.get(0).getPkBcodeId();
				status = sysBarCodeList.get(0).getStatus();
			}
			
			//入场时可改占用的，和出场时可改启用的
			if((null!=status && "1".equals(status) && "1".equals(type)) || (null!=status && "0".equals(status) && "2".equals(type))){

				localPartyInout=new LocPartyInoutEntity();
				localPartyInout.setOperateBy(UserUtil.getUserFromSession().getUserId());
				localPartyInout.setFkBcodeId(bcodeId);
				localPartyInout.setFkBranId(UserUtil.getUserFromSession().getBranId());
				localPartyInout.setOperateTime(new Date());
				localPartyInout.setFkParresId(pkParresId);
				  List<LocPartyInoutEntity> localPartyInoutList= parReserveService.localPartyInCodeList(localPartyInout);
				  LocPartyInoutEntity  localPartyInoutNew =localPartyInoutOldList.get(0);
				  if(null!=localPartyInoutNew){
					  //判断同时出场的监护人数量
					  if(null!=localPartyInoutNew.getGuaCount() && localPartyInoutNew.getGuaCount()!=Integer.parseInt(guaCount)){
						  msg="4";//出场时的监护人与入场时不匹配
						  return msg;
					  }
					  
					  if(null ==localPartyInoutList || localPartyInoutList.size()==0){
						  localPartyInoutNew.setOrdIndex(1);// 序号，1号一定是派对主人 
					  }else{
						   if(null ==localPartyInoutOldList.get(0).getOrdIndex() || 0 == localPartyInoutOldList.get(0).getOrdIndex()){
							   localPartyInoutNew.setOrdIndex(localPartyInoutList.size()+1); 
						   }
					  }
					  localPartyInoutNew.setOperateBy(UserUtil.getUserFromSession().getUserId());
					  localPartyInoutNew.setFkBcodeId(bcodeId);
					  localPartyInoutNew.setFkBranId(UserUtil.getUserFromSession().getBranId());
					  localPartyInoutNew.setOperateTime(new Date());
					  localPartyInoutNew.setFkParresId(pkParresId);
					  if(null!=type && "1".equals(type)){
						  localPartyInoutNew.setInTime(new Date());
						  if(StringUtils.isNotBlank(guaCount)){
							  localPartyInoutNew.setGuaCount(Integer.parseInt(guaCount));
						  }else{
							  localPartyInoutNew.setGuaCount(0);
						  }
					  }else{
						  localPartyInoutNew.setOutTime(new Date());
					  }
					  parReserveService.updateLocParTyInOut(localPartyInoutNew);
				  }
			}else{
				msg="3";//已进场或者已出场
			}
		}else{
			msg="2";//扫描或输入的 条码 有误，与系统条码 不匹配。
		}
		
		return msg;
	}
	
	/**
	 * 输入 预约 页面 的 装饰物 ，附加 菜单 商品 数量时，进行 update的操作
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/updateYazhengNum")
	@ResponseBody
	public String updateYazhengNum(HttpSession session 
			, ParReserveEntity parReserveEntity) throws Exception {
		String pkParresId =parReserveEntity.getPkParresId();
		parReserveEntity.setResDay(DateUtil.getDate(parReserveEntity.getPresDay()));
		UserInfo user = UserUtil.getUserFromSession();
		  String paramArray  ="";
		  String[] roomIds =parReserveEntity.getRoomIds().split(",");
			 String roomIdValue="";
			 for(int i=0;i<roomIds.length;i++){
				 if(i==roomIds.length-1){
					 roomIdValue+="'"+roomIds[i]+"'";
				 }else{
				   roomIdValue+="'"+roomIds[i]+"',";
				 }
			 }
			 parReserveEntity.setRoomId(roomIdValue);
			List<ParReserveEntity> parReserveRoomList= parReserveService.findAlreadyRoomList(parReserveEntity);
			if(null != parReserveRoomList && parReserveRoomList.size()>0){//此时间段 的房间 已经 被预约。
				HashMap<String,Object> gblprdMap =new HashMap<String,Object>();
				gblprdMap.put("parReserveRoomList",  parReserveRoomList);
			}else{
				
				if(StringUtils.isNotBlank(pkParresId)){
					parReserveService.updateParReservePkg(parReserveEntity);
				}else{
					parReserveEntity.setFkBranId(user.getBranId()); 
					pkParresId = PrimaryKeyGenerator.getPrimaryKey(BusinessType.YY, user.getAbbrCode());
					parReserveEntity.setPkParresId(pkParresId);
					parReserveEntity.setModiBy(user.getUserId());
					parReserveEntity.setModiTime(new Date());
					parReserveService.insertParReserve(parReserveEntity);
					paramArray =pkParresId+"@@";//用于前台 匹配 标志，重新加载页面
				}
				//===添加房间 预约关系 
				addParResRoom(parReserveEntity,roomIds);
				//====
		       String paramtype = parReserveEntity.getParamtype();
				if(paramtype.equals("fujia")){
					 paramArray += parReserveEntity.getBasicPkg2();
				}else if(paramtype.equals("zhuangshi")){
					  paramArray += parReserveEntity.getBasicPkg3();
				}
		}
       
		return  paramArray;
	}
	
	/**
	 * 派对 进场
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/locPartyGoIn")
	@ResponseBody
	public String locPartyGoIn(HttpSession session, HttpServletRequest request) throws Exception {
		 UserInfo user= UserUtil.getUserFromSession();
		 String type=request.getParameter("type");
		 String pkParresId=request.getParameter("pkParresId");
		 String[] barCodes=request.getParameterValues("barCodes");
		 //String[] inTimes=request.getParameterValues("inTimes");//进场时不需判断
		if(null!=barCodes && barCodes.length>0){
			//更新条码状态
			Map<String, Object> mapc = new HashMap<String, Object>();
			List<SysBarCodeEntity> sysBarCodeList = new ArrayList<SysBarCodeEntity>();
			for (int i = 0; i < barCodes.length; i++) {
				String barCode=barCodes[i];
				SysBarCodeEntity entitySysBarCode =new SysBarCodeEntity();
				entitySysBarCode.setBarCode(barCode);
				entitySysBarCode.setFkBranId(user.getBranId());
				List<SysBarCodeEntity> list = parReserveService.selectSBarCodeBrandId(entitySysBarCode);
				if(null!=list && list.size()>0 && null!=list.get(0).getStatus() && list.get(0).getStatus().equals("1")){
					sysBarCodeList.add(list.get(0));
				}
			}
			if (null != sysBarCodeList && sysBarCodeList.size() > 0) {
				mapc.put("status", "0");// （条码是否被占用的标记=1 占用，=0 未占用）
				mapc.put("barCodeList", sysBarCodeList);
				mapc.put("type", type);
				mapc.put("pkParresId", pkParresId);
				iSysBarCodeService.updateBcodeStatusBatch(mapc);
			}
		}
		PropertiesUtil prop = new PropertiesUtil();
		String batPath = prop.readSingleProps("DOOR_CONTROL_PATH", "/properties/kerrykidz.properties");
		return batPath;
	}
	
	/**
	 * 派对 出场
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/locPartyGoOut")
	@ResponseBody
	public String locPartyGoOut(HttpSession session, HttpServletRequest request) throws Exception {
		 UserInfo user= UserUtil.getUserFromSession();
		 String type=request.getParameter("type");
		 String pkParresId=request.getParameter("pkParresId");
		 String[] barCodes=request.getParameterValues("barCodes");
		 String[] outTimes=request.getParameterValues("outTimes");//出场时需判断
		 
		 boolean toOut=true;
		 if(null!=outTimes && outTimes.length>0){
				//更新条码状态
				for (int i = 0; i < outTimes.length; i++) {
					String outTime=outTimes[i];
					if(outTime==null || outTime==""){
						toOut=false;
						break;
					}
				}
			}
		 if(toOut==false){
			 return Constants.FAILURE;
		 }
		 
		if(null!=barCodes && barCodes.length>0){
			//更新条码状态
	 		Map<String, Object> mapc = new HashMap<String, Object>();
			List<SysBarCodeEntity> sysBarCodeList = new ArrayList<SysBarCodeEntity>();
			for (int i = 0; i < barCodes.length; i++) {
				String barCode=barCodes[i];
				SysBarCodeEntity entitySysBarCode =new SysBarCodeEntity();
				entitySysBarCode.setBarCode(barCode);
				entitySysBarCode.setFkBranId(user.getBranId());
				List<SysBarCodeEntity> list = parReserveService.selectSBarCodeBrandId(entitySysBarCode);
				if(null!=list && list.get(0).getStatus().equals("0")){
					sysBarCodeList.add(list.get(0));
				}
			}
			if (null != sysBarCodeList && sysBarCodeList.size() > 0) {
				mapc.put("status", "2");// （条码是否被占用的标记=1 占用，=0 未占用）
				mapc.put("barCodeList", sysBarCodeList);
				mapc.put("type", type);
				mapc.put("pkParresId", pkParresId);
				iSysBarCodeService.updateBcodeStatusBatch(mapc);
			}
		}
		PropertiesUtil prop = new PropertiesUtil();
		String batPath = prop.readSingleProps("DOOR_CONTROL_PATH", "/properties/kerrykidz.properties");
		return batPath;
	}

	
	
	/**
	 * 上传服务合同
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping(value = "/uploadFile")
	@ResponseBody
	public String uploadFile(
			@RequestParam(value = "file", required = false) MultipartFile file,HttpSession session,String pkParresId)
			throws UnsupportedEncodingException, RDPException {
		SysParaEntity para = commonService
				.findSysParaById(Constants.SYS_BASE_PATH_CONT);
		SysAttFileEntity fileEntity = new SysAttFileEntity();
		ParReserveEntity entity = new ParReserveEntity();
		String branId = UserUtil.getUserFromSession().getBranId();
		String fileName = System.currentTimeMillis() + "";
		String origFilename = file.getOriginalFilename();
		if (origFilename.lastIndexOf(".") > -1) {
			fileName = System.currentTimeMillis() + origFilename.substring(origFilename.lastIndexOf("."), origFilename.length());
		}
		String attType = "2";
		String pkAttfileId = PrimaryKeyGenerator.getRandomPrimaryKey();
		String attfilePath = fileName;
		fileEntity.setAttfileName(fileName);
		fileEntity.setAttfilePath(attfilePath);
		fileEntity.setAttType(attType);
		fileEntity.setFkBranId(branId);
		fileEntity.setPkAttfileId(pkAttfileId);
		commonService.saveAttFile(fileEntity);
		entity.setPkParresId(pkParresId);
		entity.setFkContactFile(attfilePath);;
		parReserveService.updateParReserve(entity);
		File targetFile = new File(para.getParaValue(), fileName);
		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}
		// 保存
		try {
			file.transferTo(targetFile);
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
		fileName = URLEncoder.encode(fileName, "UTF-8");
		return fileName;
	}

	
	/**
	 * 上传派对签到表
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping(value = "/uploadSignFile")
	@ResponseBody
	public String uploadSignFile(
			@RequestParam(value = "file", required = false) MultipartFile file,String pkParresId)
			throws UnsupportedEncodingException, RDPException {
		SysParaEntity para = commonService
				.findSysParaById(Constants.SYS_BASE_PATH_TSIGN);
		SysAttFileEntity fileEntity = new SysAttFileEntity();
		ParReserveEntity entity = new ParReserveEntity();
		String branId = UserUtil.getUserFromSession().getBranId();
		String fileName = System.currentTimeMillis() + "";
		String origFilename = file.getOriginalFilename();
		if (origFilename.lastIndexOf(".") > -1) {
			fileName = System.currentTimeMillis() + origFilename.substring(origFilename.lastIndexOf("."), origFilename.length());
		}
		String attType = "5";
		String pkAttfileId = PrimaryKeyGenerator.getRandomPrimaryKey();
		String attfilePath = fileName;
		fileEntity.setAttfileName(fileName);
		fileEntity.setAttfilePath(attfilePath);
		fileEntity.setAttType(attType);
		fileEntity.setFkBranId(branId);
		fileEntity.setPkAttfileId(pkAttfileId);
		commonService.saveAttFile(fileEntity);
		entity.setPkParresId(pkParresId);
		entity.setFkSignFile(attfilePath);
		parReserveService.updateParReserve(entity);
		File  targetFile = new File(para.getParaValue(), fileName);
		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}
		// 保存
		try {
			file.transferTo(targetFile);
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
		fileName = URLEncoder.encode(fileName, "UTF-8");
		return fileName;
	}


	
	/**
	 * 查找当前有效的 假期
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/findValidHoliday")
	@ResponseBody
	public HashMap<String,Object> findValidHoliday(@RequestParam(value = "pkParresIdOld") String pkParresIdOld) throws Exception {
		HashMap<String,Object> holidayMap =new HashMap<String,Object>();
		List<String> holidayList =parReserveService.findValidHoliday();
		
		/**   ================更改日期 判断
		ParReserveEntity  parreserve=parReserveService.findParReserveById(pkParresIdOld);
		if(null !=parreserve){
			String creaTime =DateUtil.formatDate("yyyy-MM-dd", parreserve.getCreaTime()); 
			String nowTime =DateUtil.formatDate("yyyy-MM-dd", new Date());
			if(!creaTime.equals(nowTime)){
			if(null !=parreserve.getResDay()){
				int dayc = DateUtil.getDiffDays(new Date(),parreserve.getResDay());
				List<String> dateDayCountList = new ArrayList<String>();
				if(dayc>=15){//举办日期>=15天后，改期后的举办日期必选>=15天
					dateDayCountList =DateUtil.getDateByDayCountList(15,new Date());
					holidayList.addAll(dateDayCountList);
				}
			}
		}
		}
		**/
		holidayMap.put("holidayList", holidayList);
		return holidayMap;
	}
	
	/**
	 * 检测 派对团体 预约的 订单 是否 支付 成功
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/checkSussesParOrder")
	@ResponseBody
	public String checkSussesParOrder(@RequestParam(value = "pkOrderId") String pkOrderId,
			@RequestParam(value = "pkParresIdOld") String pkParresIdOld,
			@RequestParam(value = "cpresDay") String cpresDay) throws Exception {
		String msg = "";
		PosOrderEntity posOrder = orderService.findOrderByPk(pkOrderId);
		if (null != posOrder) {
			if (!"1".equals(posOrder.getRetFlag())
					&& (posOrder.getOrderStatus().equals(
							ORDER_CONSTANTS.ORDER_STATUS_HAS_BEEN_PAY) || posOrder
							.getOrderStatus()
							.equals(ORDER_CONSTANTS.ORDER_STATUS_HAS_BEEN_PREPAY))) {

				double cancelMoney = 0.0;
				if (posOrder.getOrderStatus().equals(
						ORDER_CONSTANTS.ORDER_STATUS_HAS_BEEN_PAY)) {
					// 状态2 =已付款
					cancelMoney = posOrder.getAmount();
				} else if (posOrder.getOrderStatus().equals(
						ORDER_CONSTANTS.ORDER_STATUS_HAS_BEEN_PREPAY)) {
					// 状态6 =已预付
					cancelMoney = posOrder.getPaidAmount();
				}
				int dayc = DateUtil.getDiffDays(new Date(),
						DateUtil.getDate(cpresDay));
				if (dayc >= 30) {// 1)举办日期>=30天后，允许取消，退款90%
					cancelMoney = cancelMoney * 0.9;
					msg = "1@" + cancelMoney;
				} else if (30 > dayc && dayc > 15) {// 2)举办日期在15~30天之间，允许取消，退款50%
					cancelMoney = cancelMoney * 0.5;
					msg = "2@" + cancelMoney;
				} else {// 3)举办日期在15之内取消，收取100%违约金   即： 取消 不退钱
					msg = "3@0";
				}
			} else {
				msg = "4@";// 派对预约 的 订单 未支付
			}
		}
		return msg;
	}
	
	
	/**
	 * 取消 派对团体预约  已支付的 订单
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/cancelParOrder")
	@ResponseBody
	public String cancelParOrder(@RequestParam(value = "pkOrderId") String pkOrderId,
			@RequestParam(value = "pkParresIdOld") String pkParresIdOld,
			@RequestParam(value = "cancelMoneyp") String cancelMoneyp) throws Exception {
		String msg = "1";
		 ParReserveEntity parReserve = parReserveService.findParReserveById(pkParresIdOld);
		 if(null !=parReserve){
			 parReserve.setResStatus(Constants.RESERVE_STATUS_CANCEL);//取消
			 parReserveService.updateParReserve(parReserve);
		 }
		PosOrderEntity posOrder = orderService.findOrderByPk(pkOrderId);
		if(null !=posOrder){
			List<PosOrderPrdEntity> posOrdPrdList =orderService.findOrderPrdByOrderId(pkOrderId);
			String abbrCode = UserUtil.getUserFromSession().getAbbrCode();// 门店缩写
			String userId = UserUtil.getUserFromSession().getUserId();
			 Date dateNow =new Date();
			 double cancelMoney =Double.parseDouble(cancelMoneyp);
			 if(0<cancelMoney){
				 posOrder.setAmount(cancelMoney);
				 posOrder.setPaidAmount(cancelMoney);
				 posOrder.setModiBy(userId);
				 posOrder.setModiTime(dateNow);
				 posOrder.setFkOperator(userId);
				 posOrder.setOperateTime(dateNow);
				 posOrder.setRetFlag("1");//是否是退单的标记  =1 是
				 posOrder.setFkOriorderId(parReserve.getPkOrderId());//FK_ORIORDER_ID 
				orderService.createNotPayOfOrder(posOrder, posOrdPrdList, abbrCode);
				
			 }else{
				 PosOrderEntity posOrderCancel = new PosOrderEntity();
				 posOrderCancel.setOrderStatus(ORDER_CONSTANTS.ORDER_STATUS_CANCEL);//取消
				 posOrderCancel.setPkOrderId(pkOrderId);
				 orderService.updateOrder(posOrderCancel);
			 }
		}
		return msg;
	}
	

	
	
	/**
	 * 取消 派对团体预约  未支付的 订单
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/cancelNoPayParOrder")
	@ResponseBody
	public String cancelNoPayParOrder(@RequestParam(value = "pkOrderId") String pkOrderId,
			@RequestParam(value = "pkParresIdOld") String pkParresIdOld ) throws Exception {
		String msg = "success";
		 ParReserveEntity parReserve = parReserveService.findParReserveById(pkParresIdOld);
		 if(null !=parReserve){
			 parReserve.setResStatus(Constants.RESERVE_STATUS_CANCEL);//取消
			 parReserveService.updateParReserve(parReserve);
		 }
		PosOrderEntity posOrder = orderService.findOrderByPk(pkOrderId);
		if(null !=posOrder){ 
			posOrder.setOrderStatus(ORDER_CONSTANTS.ORDER_STATUS_CANCEL);//取消
			posOrder.setModiTime(new Date());
			orderService.updateOrder(posOrder);
		}
		return msg;
	}
	
	/**
	 * 2个时间数组 比较，取交集
		 * @Description   
		 * List<String>
		 * @author chenyu
		 * 2014年10月9日 下午5:46:58
		 * String[] a 是数组元素较少的。< b
	 */
	public static List<String> more(String[] b, String[] a) {
		List<String> temp = new ArrayList<String>();
		List<String> tempa = new ArrayList<String>();
		List<String> tempb = new ArrayList<String>();
		//=== 开始时间 比较
		for (int a1 = 0; a1 < a.length; a1++) {
			int  a1endStr=Integer.parseInt(a[a1].substring(a[a1].indexOf("-")+1,a[a1].length()));
			String  a1start =a[a1].substring(0,a[a1].indexOf("-"));
			for (int b1 = 0; b1 < b.length; b1++) {
				int  b1endStr=Integer.parseInt(b[b1].substring(b[b1].indexOf("-")+1,b[b1].length()));
				String  b1start =b[b1].substring(0,b[b1].indexOf("-"));
				if (a1start.equals(b1start)) {
					if(a1endStr>b1endStr){
						tempb.add(b[b1]);
					}else if(a1endStr<b1endStr){
						tempb.add(a[a1]);
					}
					break;
				}
			}
			 
		}
		//===========
		//===结束时间 比较
		for (int a1 = 0; a1 < a.length; a1++) {
			String  a1endStr=a[a1].substring(a[a1].indexOf("-")+1,a[a1].length());
			int  a1start =Integer.parseInt(a[a1].substring(0,a[a1].indexOf("-")));
			for (int b1 = 0; b1 < b.length; b1++) {
				String  b1endStr=b[b1].substring(b[b1].indexOf("-")+1,b[b1].length());
				int  b1start =Integer.parseInt(b[b1].substring(0,b[b1].indexOf("-")));
				if (a1endStr.equals(b1endStr)) {
					if(a1start>b1start){
						tempa.add(a[a1]);
					}else{
						tempa.add(b[b1]);
					}
					break;
				}  
			}
			 
		}
		temp.addAll(tempa);
		temp.addAll(tempb);
//		//===========
//		System.out.print("start1:");
//		for(String tempa1:tempa){
//			System.out.print(tempa1+",");
//		}
//		System.out.println("\n");
//		 
//		for(String tempa2:tempb){
//			System.out.print(tempa2+",");
//		}
//		
//		System.out.println("\n");
//	
//		for(String tempa3:temp){
//			System.out.print(tempa3+",");
//		}
		//====
		return temp;
	}
	
	/**
	 * 根据房间id。查询有效的房间时间段
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/getRoomTime")
	@ResponseBody
	public List<String> getRoomTime(@RequestParam(value = "pkParresId") String pkParresId, @RequestParam(value = "roomIdArray") String roomIds,
			@RequestParam(value="paiduikValue") String paiduikValue,@RequestParam(value="paiduikDate") String paiduikDate
			) throws Exception {
		HashMap<String,Object> roomIdMap =new HashMap<String,Object>();
		 UserInfo user= UserUtil.getUserFromSession();
		String[] roomIdArray = roomIds.split(",");
		roomIdMap.put("roomIdArray", roomIdArray);
		roomIdMap.put("branId", user.getBranId());
		List<String> roomTimeList =parReserveService.getRoomTime(roomIdMap);
		int length = roomIds.split(",").length;
		if (roomTimeList == null || roomTimeList.size() == 0 || roomTimeList.size() != length) {
			return null;
		}
		Map<String, Integer> sameTimes = new HashMap<String, Integer>();
		for (int i = 0; i < roomTimeList.size(); i++) {
			String[] times = roomTimeList.get(i).split(",");
			for (String time : times) {
				if (sameTimes.get(time) == null) {
					sameTimes.put(time, 1);
				} else {
					sameTimes.put(time, sameTimes.get(time) + 1);
				}
			}
		}
		roomTimeList = new ArrayList<String>();
		for (Entry<String, Integer> entry : sameTimes.entrySet()) {
				if (checkRooTime(pkParresId,paiduikDate,entry.getKey(),roomIdArray)){
					continue;
				}else{
				 roomTimeList.add(entry.getKey());
				}
		}
		return roomTimeList;
 
	}
	
	public boolean checkRooTime(String pkParresId,String paiduikDate,String time,String[] roomIdArray){
		 List<ParReserveEntity> parReserveList =parReserveService.getParReserveByDateTime(pkParresId, paiduikDate, time);
		 boolean checkRoom =false;
		 if(null!=parReserveList && parReserveList.size()>0){
			 for(int i=0;i<parReserveList.size();i++){
				 ParReserveEntity parReserve=parReserveList.get(i);
				 for(int j=0;j<roomIdArray.length;j++){
					 int count= parReserveService.findParReserveRoom(parReserve.getPkParresId(),roomIdArray[j]);
					 if(count>0){
						 checkRoom =true;
						 break;
					 }
				 }
				
			 }
			 
		 } 
		return checkRoom;
	}
	/**
	 * 更改预约日期
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/updateResDay")
	@ResponseBody
	public HashMap<String,Object> updateResDay( @RequestParam(value="pkParresId") String pkParresId,
			@RequestParam(value = "roomIdArray") String roomIds) throws Exception {
		HashMap<String,Object> roomIdMap =new HashMap<String,Object>();
		 UserInfo user= UserUtil.getUserFromSession();
		String[] roomIdArray = roomIds.split(",");
		roomIdMap.put("roomIdArray", roomIdArray);
		roomIdMap.put("branId", user.getBranId());
		List<String> roomTimeList =parReserveService.getRoomTime(roomIdMap);
		HashMap<String,Object> roomTimeMap =new HashMap<String,Object>();
		if(null !=roomTimeList && roomTimeList.size()>1){
			int roomTimeCount =roomTimeList.size();
			String roomTime0= (String)roomTimeList.get(0);
			String roomTimeLast= (String)roomTimeList.get(roomTimeCount-1);
			roomTimeList =more(roomTime0.split(","), roomTimeLast.split(","));
			if(roomTimeList.size()==0){
				roomTimeList.add(roomTime0);
			}
		}
		roomTimeMap.put("roomTimeList", roomTimeList);
		return roomTimeMap;
	}
	//pad 页面
	@RequestMapping("/reservationPage")
	public ModelAndView loadParReserve(){
		ModelAndView mav=new ModelAndView("pad/ipad_make/make_reservationList");
		UserInfo user = UserUtil.getUserFromSession();
		String uBranId =user.getBranId();
		if("ZB".equals(uBranId)){
			GblSecBranEntity secBranEntity = parReserveService.selectBranByAbbrCode("WX");
			if(null != secBranEntity){
				uBranId =secBranEntity.getPkBranId();
			}
		}
		List<ParRoomEntity> listRoom= parReserveService.findParRoom(uBranId);
		List<SecUsrEntity> listuserPar =parReserveService.listUserByRoleId("109",uBranId);//派对团体专员
		mav.addObject("listRoom", listRoom);
		mav.addObject("listuserPar", listuserPar);
		mav.addObject("userIddq", user.getUserId());
		mav.addObject("branIddq", uBranId);
		mav.addObject("dateNow", DateUtil.formatDate("yyyy-MM-dd",new Date()));
		mav.addObject("user", user);
		return mav;
	}
	/**
	 * 获取所有的房间信息
	 * @return
	 * @date: 2014年10月17日
	 */
	@RequestMapping("/getRooms")
	@ResponseBody
	public  List<ParRoomEntity>   getRooms(){
		UserInfo user = UserUtil.getUserFromSession();
		String uBranId =user.getBranId();
		if("ZB".equals(uBranId)){
			GblSecBranEntity secBranEntity = parReserveService.selectBranByAbbrCode("WX");
			if(null != secBranEntity){
				uBranId =secBranEntity.getPkBranId();
			}
		}
		List<ParRoomEntity> listRoom= parReserveService.findParRoom(uBranId);
		return listRoom;
	}
	/***
	 * 跳转到派对团体编辑的页面
	 * @return
	 * @date: 2014年10月17日
	 */
	@RequestMapping("/editReservationPage")
	public  ModelAndView  editReservationPage(@RequestParam("pkParresId") String pkParresId,
			@RequestParam("grpFlag") String parType,HttpSession session) throws RDPException{
		List<ParCTypeEntity> cTypeList= new ArrayList<ParCTypeEntity>();
		String modelView="pad/ipad_make/make_readGroup";
		if(parType.equals("0")){// =0 派对
			 cTypeList= parReserveService.findParCtypeList();
			 modelView= "pad/ipad_make/make_readPar";
		}
		 List<PosOrderEntity> posOrderList =parReserveService.findPosOrderByParresId(pkParresId);
		ParReserveEntity entity  = parReserveService.findParReserveById(pkParresId);
		String fkContactFile = entity.getFkContactFile();
		String fkSignFile = entity.getFkSignFile();
		String pkOrderId="";
		String OldpkOrderId="";
		String oldFkPriorresId="";
		if(null !=posOrderList && posOrderList.size()>0){
			PosOrderEntity posOrder =posOrderList.get(0);
			if(null !=posOrder){
				pkOrderId = posOrder.getPkOrderId();
			}
		}
		ModelAndView mav=new ModelAndView(modelView);
		String basicPkg="";
		double zhucanPrice=0;
		ParReserveEntity parreserve=null;
		String specialist ="";//派对专员
		String wristColorId ="";//腕带颜色
		
		if(StringUtils.isNotBlank(pkParresId)){
		  parreserve=parReserveService.findParReserveById(pkParresId);
		  oldFkPriorresId =parreserve.getFkPriorresId();
		  
		  if(StringUtils.isNotBlank(oldFkPriorresId)){//历史预约编号用于查询 历史订单 
			   posOrderList=parReserveService.findPosOrderByParresId(oldFkPriorresId);
			  if(null !=posOrderList && posOrderList.size()>0){
				  PosOrderEntity oldPosorder =posOrderList.get(0);
				  if(null !=oldPosorder){
					  OldpkOrderId =oldPosorder.getPkOrderId();
				  }
			  }
		  }
		  if(StringUtils.isNotBlank( parreserve.getSpecialist())){
		   specialist = parreserve.getSpecialist();
		  }
		  if(StringUtils.isNotBlank(parreserve.getWristColor())){
			  wristColorId = parreserve.getWristColor();
		  }
		  parreserve.setPresDay(DateUtil.formatDate("yyyy-MM-dd", parreserve.getResDay()));
		  parreserve.setPmodiTime(DateUtil.formatDate("yyyy-MM-dd HH:mm:ss", parreserve.getModiTime()));
		  basicPkg =parreserve.getBasicPkg();
		  String basicPkgs[] =basicPkg.split("#");
		  zhucanPrice =parReserveService.findPrdPriceByPrdId(basicPkgs[0]);
		}
		List<SecUsrEntity> listuserPar =parReserveService.listUserByRoleId("109",parreserve.getFkBranId());//派对团体专员
		List<GblParCWricorEntity> gblParCWricorList =parReserveService.findParWricorList();
		List<ParReserveRoomEntity> listparRoom= parReserveService.findParReserveRoomByparId(pkParresId);
		String rooms="";
		int i=1;
		for(ParReserveRoomEntity parRoom:listparRoom){
			rooms +=i+":"+parRoom.getRoomName()+" ";
		}
		
		parreserve.setRoomIds(rooms);
	 
		mav.addObject("zbBranid", UserUtil.getUserFromSession().getBranId()); 
		mav.addObject("listuserPar", listuserPar); 
		mav.addObject("pkParresId", pkParresId);
		mav.addObject("pkOrderId", pkOrderId);mav.addObject("OldpkOrderId", OldpkOrderId);
		mav.addObject("cTypeList", cTypeList);
		mav.addObject("parreserveOld", parreserve);
		mav.addObject("parType", parType); 
		mav.addObject("specialist", specialist); 
		mav.addObject("wristColor", wristColorId); 
		mav.addObject("gblParCWricorList", gblParCWricorList); 
		mav.addObject("zhucanPrice", zhucanPrice); 
		mav.addObject("fkSignFile",fkSignFile);
		mav.addObject("fkContactFile",fkContactFile);
		mav.addObject("keySignFile", Constants.SYS_BASE_PATH_TSIGN);
		mav.addObject("keyContactFile", Constants.SYS_BASE_PATH_CONT);
			return loadDataList( mav, parType,basicPkg,session,parreserve);
	}
	/**
	 * 跳转到新增预约列表选择界面
	 * @return
	 * @date: 2014年10月20日
	 */
	@RequestMapping("/ToReservationPage")
	public ModelAndView  ToReservationPage(){
		ModelAndView mav=new ModelAndView("pad/ipad_mship/reservation_selectPage");
		UserInfo user = UserUtil.getUserFromSession();
		String uBranId =user.getBranId();
		if("ZB".equals(uBranId)){
			GblSecBranEntity secBranEntity = parReserveService.selectBranByAbbrCode("WX");
			if(null != secBranEntity){
				uBranId =secBranEntity.getPkBranId();
			}
		}
		List<ParRoomEntity> listRoom= parReserveService.findParRoom(uBranId);
		mav.addObject("listRoom", listRoom);
		mav.addObject("userIddq", user.getUserId());
		mav.addObject("branIddq", uBranId);
		return mav;
	}
	
	@RequestMapping("/printParHetong")
	@ResponseBody
	public  void   printParHetong(@RequestParam(value="pkParresId") String pkParresId,HttpServletResponse response) throws Exception {
		ParReserveEntity parReserve =  parReserveService.findParReserveById(pkParresId);
		String presDay =DateUtil.formatDate("yyyy-MM-dd", parReserve.getResDay());
		String yuankaishit =parReserve.getResTimeS();
		String yuanend =parReserve.getResTimeE();
		String resTimeS =yuankaishit.substring(0,2)+":"+yuankaishit.substring(2,4);
		String resTimeE =yuanend.substring(0,2)+":"+yuanend.substring(2,4);
		String fkMemId =parReserve.getFkMemId();
		String conAge ="";
		if(StringUtils.isNotBlank(fkMemId)){
			CusMemEntity cusMem=parReserveService.findMemberById(fkMemId);
			conAge =cusMem.getAge();
		}
		String parType ="";
		 String basicPkg =parReserve.getBasicPkg();
		 String zhushi1="";String zhushi2 ="";String zhushi3 ="";String peicai="";String yinliao="";
		 String taocan ="";
		 if(StringUtils.isNotBlank(basicPkg)){
			 List<GblScmPrdEntity> listGblScmTaocan=null;
			   parType =parReserve.getGrpFlag();
			 if("1".equals(parType)){//团体 2主食，1配菜，1饮料
				 if(!basicPkg.equals(Constants.RESERVE_PRDCATE_4NOMEAL)){//排除 团体不含餐
					 listGblScmTaocan =getUpdateTaocanList(basicPkg,parType);
					  if(null != listGblScmTaocan && listGblScmTaocan.size()>0){
						   for(int i=0;i<listGblScmTaocan.size();i++){
							   GblScmPrdEntity scmPrd =listGblScmTaocan.get(i);
							   String prdName =scmPrd.getPrdName();
							  if(i==0)zhushi1=prdName;
							  if(i==1)zhushi2=prdName;
							  if(i==2)peicai=prdName;
							  if(i==3)yinliao=prdName;
						   }
					  }
				 }
				}else if("0".equals(parType)){//派对 3主食，1配菜，1饮料
					 listGblScmTaocan =getUpdateTaocanList(basicPkg,parType);
					  if(null != listGblScmTaocan && listGblScmTaocan.size()>0){
						   for(int i=0;i<listGblScmTaocan.size();i++){
							   GblScmPrdEntity scmPrd =listGblScmTaocan.get(i);
							   String prdName =scmPrd.getPrdName();
							     if(i==0)zhushi1=prdName;
								  if(i==1)zhushi2=prdName;
								  if(i==2)zhushi3=prdName;
								  if(i==3)peicai=prdName;
								  if(i==4)yinliao=prdName;
						   }
					  }
				}
			 
			 taocan = zhushi1 +";"+zhushi2+";"+zhushi3+";"+peicai+";"+yinliao;
		 }
		 GblScmPrdEntity scmprd =new GblScmPrdEntity();
		 scmprd.setBasicPkg2(parReserve.getBasicPkg2());
		 GblScmPrdEntity fujiaScmPrd= addPageFujia(scmprd,"");
		 String fujia="";
		 if(null !=fujiaScmPrd && null !=fujiaScmPrd.getResults()){
			 @SuppressWarnings("unchecked")
			List<GblScmPrdEntity> fujiaList =fujiaScmPrd.getResults();
			 for(int j=0;j<fujiaList.size();j++){
				   GblScmPrdEntity scmPrd =fujiaList.get(j);
				   String prdName =scmPrd.getPrdName();
				   if(null !=scmPrd.getQuantity() && scmPrd.getQuantity()>0){
					   String prdCount =scmPrd.getQuantity()+"";
						 fujia +=prdName +"["+prdCount+"]; ";
				   }
				
			 }
		 }
		 //========装饰物
		 scmprd =new GblScmPrdEntity();
		 scmprd.setBasicPkg2(parReserve.getBasicPkg2());
		 GblScmPrdEntity zhuangswScmPrd= addPageZhuangshi(scmprd,"");
		 String zhuangshiwu="";
		 
		 if(null !=zhuangswScmPrd && null !=zhuangswScmPrd.getResults()){
			 @SuppressWarnings("unchecked")
			List<GblScmPrdEntity> zhuangsList =zhuangswScmPrd.getResults();
			 for(int j=0;j<zhuangsList.size();j++){
				   GblScmPrdEntity scmPrd =zhuangsList.get(j);
				   String prdName =scmPrd.getPrdName();
				   if(null !=scmPrd.getQuantity() && scmPrd.getQuantity()>0){
					   String prdCount =scmPrd.getQuantity()+"";
					   zhuangshiwu +=prdName +"["+prdCount+"]; ";
				   }
			 }
		 }
		   String allMount=""; 
		 List<PosOrderEntity> posOrderList =null;
				posOrderList =parReserveService.findPosOrderByParresId(pkParresId);
				if(null !=posOrderList && posOrderList.size()>0){
					PosOrderEntity posOrderOld =posOrderList.get(0);
						if(null !=posOrderOld){
							allMount =posOrderOld.getAmount()+"";
							 
						}
					}
				
				List<ParReserveRoomEntity> listparRoom= parReserveService.findParReserveRoomByparId(parReserve.getPkParresId());
				String rooms="";
				int i=1;
				for(ParReserveRoomEntity parRoom:listparRoom){
					rooms +=i+":"+parRoom.getRoomName()+" ";
				}
		ParHetongWordModel parHetong =new ParHetongWordModel( parReserve.getSubject(),parReserve.getConName(), parReserve.getChdName(),
				parReserve.getConMobile(),parReserve.getConEmail(),presDay,resTimeS,resTimeE,
				parReserve.getResMemCnt()+"",
				conAge,parReserve.getComments(),taocan , fujia,  parType,
	    		     zhuangshiwu,  allMount,  "",rooms,
	    		  "parHetong",pkParresId);
		String pathFile = CreateWD2003Util.createParHetongWord(parHetong);//根据 word模版，生成word2003 文件
		File fil = new File(pathFile);
		if (fil.exists()) {
			String attFile ="KerryKidz-parHetong_"+pkParresId+".doc";
				response.setContentType("application/msword;charset=UTF-8");

			//URLEncoder.encode(attFile, "UTF-8")解决中文乱码
			response.addHeader("Content-Disposition", "attachment;filename=\""
					+ URLEncoder.encode(attFile, "UTF-8")+"\"");
			response.addHeader("Content-Length", "" + fil.length() + "");
			response.setContentType("application/x-download");

			byte[] buffer = new byte[4096];// 缓冲区
			BufferedOutputStream output = null;
			BufferedInputStream input = null;
			try {
				output = new BufferedOutputStream(response.getOutputStream());
				input = new BufferedInputStream(new FileInputStream(fil));
				int n = -1;
				while ((n = input.read(buffer, 0, 4096)) > -1) {
					output.write(buffer, 0, n);
				}
				output.flush();
				response.flushBuffer();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				// 关闭流
				if (input != null)
					input.close();
				if (output != null)
					output.close();
			}
		}
	}
	
	/**
	* @Title: Pad new团体预约详细页面     
	* @Description: <p>团体预约详细页面<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/toPadTuanTiReserveNew")
	public ModelAndView toPadTuanTiReserveNew(@RequestParam("parType") String parType,
			@RequestParam("pkParresId") String pkParresId,@RequestParam("pkOrderId") String pkOrderId )throws RDPException{
			ModelAndView mav=new ModelAndView("pad/ipad_mship/order_add");
			ParReserveEntity parreserve=null;
			String basicPkg="";
			List<ParReserveRoomEntity> parReserveRoomList=new ArrayList<ParReserveRoomEntity>();
			if(StringUtils.isNotBlank(pkParresId)){
			  parreserve=parReserveService.findParReserveById(pkParresId);
			  basicPkg =parreserve.getBasicPkg();
			  parreserve.setPresDay(DateUtil.formatDate("yyyy-MM-dd", parreserve.getResDay()));
			  parReserveRoomList= parReserveService.findParReserveRoomByparId(pkParresId);
			  
			}
			String guanliDetail="";
			if(StringUtils.isNotBlank(pkOrderId) && pkOrderId.indexOf("@")>0){//档案管理 --》派对，团体预约 详细页面 点击 过来的 ，订单Id
				String[] pkorderIds =pkOrderId.split("@");
				guanliDetail="guanliDetail";
				if(pkorderIds.length>1){
					pkOrderId = pkorderIds[1];
				}else{
					pkOrderId ="";
				}
				
			}
			mav.addObject("parReserveRoomList", parReserveRoomList);
			mav.addObject("pkParresId", pkParresId);
			mav.addObject("pkOrderId", pkOrderId);
			mav.addObject("guanliDetail", guanliDetail);//此参数  方便 ，返回 到 档案管理 --》预约管理 页面
			mav.addObject("parreserveOld", parreserve);
			mav.addObject("parType", parType); 
				return loadDataList( mav, parType,basicPkg,null,parreserve);
	}
	
	/**
	* @Title: Pad new团体派对详细页面     
	* @Description: <p>派对预约详细页面<p>
	* @date: 2014年8月5日
	* @return: ModelAndView
	* @throws 
	*
	 */
	@RequestMapping("/toPadReserveNew")
	public ModelAndView toPadReserveNew(@RequestParam("parType") String parType,@RequestParam("pkParresId") String pkParresId,
			@RequestParam("pkOrderId") String pkOrderId,HttpSession session) throws RDPException{
			ModelAndView mav=new ModelAndView("pad/ipad_mship/order_add_x");
			String basicPkg="";
			ParReserveEntity parreserve=null;
			List<ParReserveRoomEntity> parReserveRoomList=new ArrayList<ParReserveRoomEntity>();
			if(StringUtils.isNotBlank(pkParresId)){
			  parreserve=parReserveService.findParReserveById(pkParresId);
			  parreserve.setPresDay(DateUtil.formatDate("yyyy-MM-dd", parreserve.getResDay()));
			  parReserveRoomList= parReserveService.findParReserveRoomByparId(pkParresId);
			  basicPkg =parreserve.getBasicPkg();
			}
			
			String guanliDetail="";
			List<ParCTypeEntity> cTypeList= parReserveService.findParCtypeList();
			if(StringUtils.isNotBlank(pkOrderId) && pkOrderId.indexOf("@")>0){//档案管理 --》派对，团体预约 详细页面 点击 过来的 ，订单Id
				String[] pkorderIds =pkOrderId.split("@");
				guanliDetail="guanliDetail";
				if(pkorderIds.length>1){
					pkOrderId = pkorderIds[1];
				}else{
					pkOrderId ="";
				}
			}
			
			mav.addObject("parReserveRoomList", parReserveRoomList);
			mav.addObject("pkParresId", pkParresId);
			mav.addObject("pkOrderId", pkOrderId);
			mav.addObject("cTypeList", cTypeList);
			mav.addObject("guanliDetail", guanliDetail);//此参数  方便 ，返回 到 档案管理 --》预约管理 页面
			mav.addObject("parreserveOld", parreserve);
			mav.addObject("parType", parType); 
				return loadDataList( mav, parType,basicPkg,session,parreserve);
	}
	/**
	 * 获取派对或团体的主食套餐信息
	 * @param basicPkg  含餐信息
	 * @param parType  派对或团体
	 * @return
	 * @date: 2014年10月31日
	 */
	@RequestMapping("/getHoldFood")
	@ResponseBody
	public  List<GblScmPrdEntity> getHoldFood(@RequestParam("pkParresId")String pkParresId,@RequestParam("")String parType){
		  ParReserveEntity  parreserve=parReserveService.findParReserveById(pkParresId);
		  String   basicPkg =parreserve.getBasicPkg();
		  return getUpdateTaocanList(basicPkg,parType);
	}
	
	/**
	 * 团体 点击 “确认预定” 按钮 预约订单
		 * @Description   
		 * HashMap<String,Object>
		 * @author chenyu
		 * 2014年8月21日 下午2:01:33
		 *  okparTuantiOperateOrder(session,parReserve,"",null,null,false,null);
	 */
	HashMap<String,Object> okparTuantiOperateOrder(HttpSession session,ParReserveEntity parReserve,String orderStatus,
			List<ParReserveRoomEntity> reserveRoomList,Double oldPaidAmount,boolean copyHisFlag,
			ParReserveEntity parReserveOld,String okOrderStatus ) throws Exception{
		String abbrCode = UserUtil.getUserFromSession().getAbbrCode();// 门店缩写
		String branId = UserUtil.getUserFromSession().getBranId();// 门店编号
		String userId = UserUtil.getUserFromSession().getUserId();
		String pkParresId =parReserve.getPkParresId();
		String orderPk=parReserve.getPkOrderId();
		boolean isTuantiyuding =false;//团体确认预定 标志。
		List<PosOrderEntity> posOrderList =null;
		if(StringUtils.isBlank(orderPk)){
			posOrderList =parReserveService.findPosOrderByParresId(pkParresId);
			
			if(null !=posOrderList && posOrderList.size()>0){
				PosOrderEntity posOrderOld =posOrderList.get(0);
				if(null !=posOrderOld){
					orderPk =posOrderOld.getPkOrderId();
					parReserve.setPkOrderId(orderPk);
					if(StringUtils.isBlank(orderStatus)){
						isTuantiyuding =true;
						orderStatus =ORDER_CONSTANTS.ORDER_STATUS_NOT_PAY;//团体确认预定 时，订单状态设置 未付款
					}
				}
			}
		}
		if(StringUtils.isBlank(orderStatus)){// 当 预约 未生成 订单时 的设置
			isTuantiyuding =true;
			orderStatus ="7";
		}
		List<PosOrderPrdEntity> products =null;
		double amount=0.00;
		double zhucanPrice =0;
		if(orderStatus.equals(ORDER_CONSTANTS.ORDER_STATUS_NOT_PAY) ||orderStatus.equals(ORDER_CONSTANTS.ORDER_STATUS_PREPAY)|| orderStatus.equals("7")){//未付款,草稿状态时，可以批量修改订单明细
		  products =new ArrayList<PosOrderPrdEntity>();
		if(StringUtils.isNotBlank(parReserve.getBasicPkg())  ){
			String basicPkgs[] =parReserve.getBasicPkg().split("#");
			  zhucanPrice =parReserveService.findPrdPriceByPrdId(basicPkgs[0]);
			PosOrderPrdEntity posOrderPrd=new PosOrderPrdEntity();
			posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
			posOrderPrd.setFkPrdId(basicPkgs[0]);
			int pcount =parReserve.getResMemCnt();
			posOrderPrd.setOrdIndex(1);
			posOrderPrd.setPrice(zhucanPrice);
			posOrderPrd.setDisPrice(zhucanPrice*pcount);
			posOrderPrd.setPkOrderId(orderPk);
			
			posOrderPrd.setCount(pcount);
			amount+=zhucanPrice*pcount;
			products.add(posOrderPrd);
		}
		int i=1;
		if(StringUtils.isNotBlank(parReserve.getBasicPkg2())){
			String basicPkgs2[] =parReserve.getBasicPkg2().split(",");
			for(String basicPkg2:basicPkgs2){
				i++;
				PosOrderPrdEntity posOrderPrd=new PosOrderPrdEntity();
				posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
				if(StringUtils.isNotBlank(basicPkg2)){
					String basicPkg2Ids[]=basicPkg2.split("#");
					if(StringUtils.isNotBlank(basicPkg2Ids[1]) && Integer.parseInt(basicPkg2Ids[1])>0){
						double fujiaPrice =parReserveService.findPrdPriceByPrdId(basicPkg2Ids[0]);
						int pcount=Integer.parseInt(basicPkg2Ids[1]);
						posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
						posOrderPrd.setFkPrdId(basicPkg2Ids[0]);
						posOrderPrd.setOrdIndex(i);
						posOrderPrd.setPrice(fujiaPrice);
						posOrderPrd.setDisPrice(fujiaPrice * pcount);
						posOrderPrd.setPkOrderId(orderPk);
						posOrderPrd.setCount(Integer.parseInt(basicPkg2Ids[1]));
						amount+=fujiaPrice * pcount;
						products.add(posOrderPrd);
					}
				}
			}
		}
		if(StringUtils.isNotBlank(parReserve.getBasicPkg3())){
			String basicPkgs3[] =parReserve.getBasicPkg3().split(",");
			for(String basicPkg3:basicPkgs3){
				i++;
				PosOrderPrdEntity posOrderPrd=new PosOrderPrdEntity();
				posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
				if(StringUtils.isNotBlank(basicPkg3)){
					String basicPkg3Ids[]=basicPkg3.split("#");
					if(StringUtils.isNotBlank(basicPkg3Ids[1]) && Integer.parseInt(basicPkg3Ids[1])>0){
						double qiQiuPrice =parReserveService.findPrdPriceByPrdId(basicPkg3Ids[0]);
						int pcount =Integer.parseInt(basicPkg3Ids[1]);
						posOrderPrd.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
						posOrderPrd.setFkPrdId(basicPkg3Ids[0]);
						posOrderPrd.setPkOrderId(orderPk);
						posOrderPrd.setOrdIndex(i);
						posOrderPrd.setPrice(qiQiuPrice);
						posOrderPrd.setDisPrice(qiQiuPrice * pcount);
						posOrderPrd.setCount(pcount);
						amount+=qiQiuPrice * pcount;
						products.add(posOrderPrd);
					}
				}
			}
		}
		}
		
		PosOrderEntity order=new PosOrderEntity();
		order.setOrderType(ORDER_CONSTANTS.ORDER_TYPE_PARTY);
		order.setFkParresId(pkParresId);
		order.setOrderStatus(orderStatus);//订单状态
		order.setCusName(parReserve.getConName());
		order.setFkOperator("");
		order.setModiBy(parReserve.getModiBy());
		order.setModiTime(new Date());
		order.setRetFlag("0");//是否是退单的标记   =0 否 
		if(null !=parReserve.getAmount() && parReserve.getAmount()>0){
			order.setAmount(parReserve.getAmount());
		}else{
			order.setAmount(amount);
		}
		double newPaidAmount =0.0;
        if(null == parReserve.getPaidAmount() && !isTuantiyuding  && null !=reserveRoomList){
        	 newPaidAmount =getpaidAmount(reserveRoomList,zhucanPrice);
        	 order.setPaidAmount(newPaidAmount);
        }else{
        	order.setPaidAmount(parReserve.getPaidAmount());
        }
        if(isTuantiyuding){
        	order.setOrderStatus(orderStatus);//订单状态
        	order.setPaidAmount(0.0);
        }
        if(StringUtils.isNotBlank(parReserve.getFkParcpnId())){
        	order.setFkParcpnId(parReserve.getFkParcpnId());
        }
        Date dateNow =new Date();
        order.setModiBy(userId);
        order.setModiTime(dateNow);
        order.setFkOperator(userId);
		order.setOperateTime(dateNow);
		order.setFkBranId(branId);
		order.setPkOrderId(parReserve.getPkOrderId());
		String OldpkOrderId =parReserve.getPkOrderId();
		if(null !=oldPaidAmount && null !=reserveRoomList && copyHisFlag){
			 newPaidAmount =getpaidAmount(reserveRoomList,zhucanPrice);
			//3 如果新订单需要预付定金，新订单状态“未预付”，原订单状态保持不变直至新订单预付成功后，原订单“取消”；24小时之内新订单未预付，新订单删除
			if(newPaidAmount> oldPaidAmount){
				order.setOrderStatus(ORDER_CONSTANTS.ORDER_STATUS_PREPAY);//  新订单状态“未预付”
				order.setPaidAmount(newPaidAmount);
			
				
				 orderPk=orderService.createNotPayOfOrder(order, products, abbrCode);
				
			}else{
				String oldstatusOrder=ORDER_CONSTANTS.ORDER_STATUS_PREPAY;
				if(null !=parReserveOld){
					String pkOldrParReserveId =parReserveOld.getPkParresId();//老的 预约编号
					posOrderList =parReserveService.findPosOrderByParresId(pkOldrParReserveId);//老订单
					if(null !=posOrderList && posOrderList.size()>0){
						PosOrderEntity posOrderOld =posOrderList.get(0);
					if(null !=posOrderOld){
						oldstatusOrder =posOrderOld.getOrderStatus();
					}
					}
				}
				 
				//2. 如果新订单不需要重新预付定金，新订单状态为“预付”，原订单“取消”
				order.setOrderStatus(oldstatusOrder);//  新订单状态“预付”
				order.setPaidAmount(newPaidAmount);
				 orderPk=orderService.createNotPayOfOrder(order, products, abbrCode);
				 posOrderList = parReserveService.findPosOrderByParresId(parReserve.getFkPriorresId());
				 if(null !=posOrderList && posOrderList.size()>0){
					 PosOrderEntity orderOld =posOrderList.get(0);
					 if(null !=orderOld){
						 
						 orderService.removeOrderPrdByOrderId(orderOld.getPkOrderId());
						 orderOld.setOrderStatus(ORDER_CONSTANTS.ORDER_STATUS_CANCEL);
						 orderOld.setModiTime(new Date());
						 orderService.updateOrder(orderOld);
						 if(null !=parReserveOld){
							 parReserveService.deleteParRoomByParId(parReserveOld.getPkParresId());//先删除老的 房间记录
							 parReserveOld.setResStatus(Constants.RESERVE_STATUS_CANCEL);
							 parReserveService.updateParReserve(parReserveOld);
						 }
					 }
				 }
			}
		}else{
			if(StringUtils.isNotBlank(orderPk)){
				order.setOrderStatus("6");//=6 派对团体未结算
				if(null ==products){
				   orderService.updateOrder(order);
				}else{
					order.setModiTime(new Date());
			    	orderService.updateOrder(order, products);
				}
			}else{
				order.setOrderStatus("7");//订单草稿状态
			  orderPk=orderService.createNotPayOfOrder(order, products, abbrCode);
			}
		}
		if(null !=parReserveOld){
		String pkOldrParReserveId =parReserveOld.getPkParresId();//老的 预约编号
		if(parReserve.getPkParresId().equals(parReserveOld.getPkParresId())){
			pkOldrParReserveId =parReserveOld.getFkPriorresId();
		}
		List<PosOrderPaymentEntity> NeworderPaymentList =iPaymentService.findByOrderPk(orderPk);//新订单支付记录列表
		posOrderList =parReserveService.findPosOrderByParresId(pkOldrParReserveId);//老订单
		if(null !=posOrderList && posOrderList.size()>0){
			PosOrderEntity posOrderOld =posOrderList.get(0);
		if(null !=posOrderOld){
			List<PosOrderPaymentEntity> orderPaymentList =iPaymentService.findByOrderPk(posOrderOld.getPkOrderId());//老订单支付记录列表
				 if(null !=orderPaymentList && orderPaymentList.size()>0){
					 if(null ==NeworderPaymentList || NeworderPaymentList.size()< orderPaymentList.size()){// 当新订单支付记录为空时，从老订单记录copy过来
					 for(int pp=0;pp<orderPaymentList.size();pp++){
						 PosOrderPaymentEntity payment=orderPaymentList.get(pp);
						 payment.setFkOrderId(orderPk);
						 iPaymentService.createRepay(payment);
					 }
					 }
				 }
			}
			}
		}
		if(null!=parReserve && parReserve.getResStatus().equals(Constants.RESERVE_STATUS_NOPREPAY)){
			SmsSendVO smsVo =new SmsSendVO();
			smsVo.setSmsMob(parReserve.getConMobile());
			String msg ="亲爱的客户您好，很高兴能为您提供派对服务，请在未来24小时内完成派对定金支付，我们将为您的派对做充足的准备，逾期则自动取消，谢谢，无锡昕星园。";
			smsVo.setSmsText(msg);
			iSmsSendService.sendSMS(smsVo);//发短信
			
			// 发Email
			String comEmail =parReserve.getConEmail();
			if(StringUtils.isNotBlank(parReserve.getConEmail())){
				Pattern pattern = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
				Matcher matcher = pattern.matcher(comEmail);
				 if(matcher.matches()){
					 msg ="";
					 msg="亲爱的客户您好，<br/>";
					 msg +="昕星园很高兴能为您提供专业的儿童派对服务，我们已向系统提交了您的派对预定，请您在收到我们邮件后的24小时内至昕星园完成派对定金预付，我们将会为您的派对做充足的准备。温馨提示：预期未进行预付系统将自动取消该预定。<br/>";
					 msg +="感谢您对我们的信任，我们将竭力为您的孩子及您邀请的亲友举办一场愉快难忘的派对。<br/>";
					 msg +="欢迎你们来到昕星园!<br/>"; 
					 msg +="派对预定电话：0510-81833508"; 
					 MailUtil.sendHTMLMail(comEmail,"KerryKidz 游乐园 预约通知",msg);
				 }
			}
		}
		parReserve.setResStatus(Constants.RESERVE_STATUS_TOBECONFIRM);
		 parReserveService.updateParReserve(parReserve);
		HashMap<String,Object> putObj=new HashMap<String,Object>();
		
		putObj.put("OldpkOrderId", OldpkOrderId);
		putObj.put("pkParresId", pkParresId);
		putObj.put("orderPk",  orderPk);
		putObj.put("posOrderOld",  order);
		putObj.put("posOrderOldStatus",  order.getOrderStatus());
		putObj.put("zhucanPrice",zhucanPrice);
		return putObj;
	}
	
	/**
	 *  导出 供应商 订单 Excel
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping(value="/expParSupplyPrd",method=RequestMethod.POST)
	@ResponseBody
	public void expParSupplyPrd(@RequestParam("pkParresId") String pkParresId,HttpServletResponse response)throws RDPException{
		try {
			ParReserveEntity parReserve =parReserveService.findParReserveById(pkParresId);
			  ParSupperExportVo p1= new ParSupperExportVo();
			  //==
				String parType ="";
				 String basicPkg =parReserve.getBasicPkg();
				 List<GblScmPrdEntity> gList =new ArrayList<GblScmPrdEntity>();
				 List<GblScmPrdEntity> zhuangShiPrdList =new ArrayList<GblScmPrdEntity>();
				 if(StringUtils.isNotBlank(basicPkg)){
					 List<GblScmPrdEntity> listGblScmTaocan=null;
					   parType =parReserve.getGrpFlag();
					  
					 if("1".equals(parType)){//团体 2主食，1配菜，1饮料
						 if(!basicPkg.equals(Constants.RESERVE_PRDCATE_4NOMEAL)){//排除 团体不含餐
							 listGblScmTaocan =getUpdateTaocanList(basicPkg,parType);
							  if(null != listGblScmTaocan && listGblScmTaocan.size()>0){
								   for(int i=0;i<listGblScmTaocan.size();i++){
									   GblScmPrdEntity scmPrd =listGblScmTaocan.get(i);
									   scmPrd.setPurCnt(1);
									   String prdName =scmPrd.getPrdName();
									  if(i==0){
										  scmPrd.setPrdName("主食1："+prdName);
									  }
									  if(i==1){
										  scmPrd.setPrdName("主食2："+prdName);
									  }
									  if(i==2){
										  scmPrd.setPrdName("配菜："+prdName);
									  }
									  if(i==3){
										  scmPrd.setPrdName("饮料："+prdName);
									  }
									  gList.add(scmPrd);
								   }
							  }
						 }
						}else if("0".equals(parType)){//派对 3主食，1配菜，1饮料
							 listGblScmTaocan =getUpdateTaocanList(basicPkg,parType);
							  if(null != listGblScmTaocan && listGblScmTaocan.size()>0){
								   for(int i=0;i<listGblScmTaocan.size();i++){
									   GblScmPrdEntity scmPrd =listGblScmTaocan.get(i);
									   String prdName =scmPrd.getPrdName();
									   scmPrd.setPurCnt(1);
									     if(i==0){
									    	 scmPrd.setPrdName("主食1："+prdName);
									     }
										  if(i==1){
											  scmPrd.setPrdName("主食2："+prdName);
										  }
										  if(i==2){
											  scmPrd.setPrdName("主食3："+prdName);
										  }
										  if(i==3){
											  scmPrd.setPrdName("配菜："+prdName);
										  }
										  if(i==4){
											  scmPrd.setPrdName("饮料："+prdName);
										  }
										  gList.add(scmPrd);
								   }
							  }
						}
					 
				 }
				 GblScmPrdEntity scmprd =new GblScmPrdEntity();
				 scmprd.setBasicPkg2(parReserve.getBasicPkg2());
				 GblScmPrdEntity fujiaScmPrd= addPageFujia(scmprd,"");
				 if(null !=fujiaScmPrd && null !=fujiaScmPrd.getResults()){
					 @SuppressWarnings("unchecked")
					List<GblScmPrdEntity> fujiaList =fujiaScmPrd.getResults();
					 for(int j=0;j<fujiaList.size();j++){
						   GblScmPrdEntity scmPrd =fujiaList.get(j);
						   int prdCount =scmPrd.getQuantity();
						   String prdName =scmPrd.getPrdName();
						   if(prdCount>0){
							   scmPrd.setPrdName("附加："+prdName);
							   scmPrd.setPurCnt(prdCount);
							   gList.add(scmPrd);
						   }
						  
						
					 }
				 }
				 //========装饰物
				 scmprd =new GblScmPrdEntity();
				 scmprd.setBasicPkg2(parReserve.getBasicPkg2());
				 GblScmPrdEntity zhuangswScmPrd= addPageZhuangshi(scmprd,"");
				 
				 if(null !=zhuangswScmPrd && null !=zhuangswScmPrd.getResults()){
					 @SuppressWarnings("unchecked")
					List<GblScmPrdEntity> zhuangsList =zhuangswScmPrd.getResults();
					 for(int j=0;j<zhuangsList.size();j++){
						   GblScmPrdEntity scmPrd =zhuangsList.get(j);
						   int prdCount =scmPrd.getQuantity();
						   if(prdCount>0){
							   scmPrd.setPurCnt(prdCount);
							   zhuangShiPrdList.add(scmPrd);
						   }
						  
					 }
				 }
			  //==
	        p1.setOptTime(DateUtil.formatDate("yyyy.MM.dd", new Date()));
	        String timeS=parReserve.getResTimeS();
	        timeS =timeS.substring(0,2)+":"+timeS.substring(2,4);
	        String timeEnd =parReserve.getResTimeE();
	        timeEnd =timeEnd.substring(0,2)+":"+timeEnd.substring(2,4);
	        String parDate =DateUtil.formatDate("yyyy-MM-dd", parReserve.getResDay())+" "+timeS+"~"+timeEnd;
	        UserInfo user =UserUtil.getUserFromSession();p1.setParDate(parDate);
			p1.setOptUser(user.getName());p1.setBrandName(user.getBranName());
			p1.setAddress("");p1.setPeopleCount(parReserve.getResMemCnt());p1.setAddress(user.getContAddr());
			p1.setParSupList(gList);p1.setType("食品");p1.setParSubject(parReserve.getSubject());
			
			ParSupperExportVo p2= new ParSupperExportVo();
	        p2.setOptTime(DateUtil.formatDate("yyyy.MM.dd", new Date()));p2.setParDate(parDate);
			p2.setOptUser(user.getName());p2.setParSupList(zhuangShiPrdList);p2.setType("装饰物");
			p2.setAddress("");p2.setPeopleCount(parReserve.getResMemCnt());p2.setAddress(user.getContAddr());
			p2.setParSubject(parReserve.getSubject());p2.setBrandName(user.getBranName());
			 List<ParSupperExportVo> list = new ArrayList<ParSupperExportVo>();
			 list.add(p1);
			 list.add(p2);
	    //=========================    
	        //sheet的名称  
	        List<String> listSheetNames = new ArrayList<String>();  
	        listSheetNames.add("食品类");  
	        listSheetNames.add("非食品类");  
	        String pathFile =parReserveService.expParSupplyPrd( list, listSheetNames);;
	    	
	    	File fil = new File(pathFile);
			if (fil.exists()) {
				response.setContentType("application/msword;charset=UTF-8");
			//URLEncoder.encode(attFile, "UTF-8")解决中文乱码
			response.addHeader("Content-Disposition", "attachment;filename=\""
					+ URLEncoder.encode("parSupplyTemplate.xls", "UTF-8")+"\"");
			response.addHeader("Content-Length", "" + fil.length() + "");
			response.setContentType("application/x-download");

			byte[] buffer = new byte[4096];// 缓冲区
			BufferedOutputStream output = null;
			BufferedInputStream input = null;
			try {
				output = new BufferedOutputStream(response.getOutputStream());
				input = new BufferedInputStream(new FileInputStream(fil));
				int n = -1;
				while ((n = input.read(buffer, 0, 4096)) > -1) {
					output.write(buffer, 0, n);
				}
				output.flush();
				response.flushBuffer();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				// 关闭流
				if (input != null)
					input.close();
				if (output != null)
					output.close();
			}
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
